In this section of tutorial I will show you how you can create a breadcrumb dynamically in WordPress. For this we will create a plug-in of WordPress.
First we need to understand what breadcrumb is all about and why we use it.
Breadcrumb is a navigation system which ideally resides below top menu. This one is used to give users easy access to the pages which he already visited. One does not have to press back button to navigate to previous page. Seeing the navigation structure one can click and directly jump to the page one wants to go to.
Suppose you are visiting a website and the content structure is like this.
Home page and then about page and inside about us there is company information page.
So the breadcrumb will be like this.
Home>>about Us>>Company Information
So, in this topic will we will learn how to generate breadcrumb dynamically in WordPress.
Step – 1
Create a folder called ace_breadcrumb (you can give any name, just bear in mind that your plugin name should be unique)
Step –2
Now create a file called ace_breadcrumb.php and put the file inside the folder you just crated above.
Step –4
Write this code inside your page.
<?php
/*
Plugin Name: Ace Breadcrumb
Description: This is a simple plugin to dynamically generate breadcrumb
Plugin_URI: http://www.acesoftech.com
Author:Asraf Ali
Version: 1.0
*/
?>
Here I am assuming that you are working in local machine and XAMPP server.
So I am placing this file here
C:XAMPP/htdocs/wordpress/wp-content/plugin
Step –4
Go to admin dashboard and plugin and then check your plugin name.
You can see your plug-in name right? Great!
Now activate it.
Since there is no any functional code written inside the plugin, it’s not going to do any work.
OK, so now it’s time to give our plugin some power to do something.
Open your ace_breadcrumb.php file which is inside the pluging folder. And edit it.
<?php
/*
Plugin Name: Ace Breadcrumb
Description: This is a simple plugin to dynamically generate breadcrumb
Plugin_URI: http://www.acesoftech.com
Author:Asraf Ali
Version: 1.0
*/
Function ace_breadcrumb(){
If(is_homepage())
?>
You are here: Home>>
<?php
}
Else{
$ace_id= get_the_id();
}
}
?>
If you want to get WordPress training in Kolkata, you can get the details from here.
Comments
Post a Comment