Posted On January 5, 2012

WordPress breadcrumb navigation PHP code

admin 0 comments

Here’s some really simple PHP code to generate breadcrumb navigation in WordPress. It only supports navigation down two levels – i.e. you have a page that defines a section of a site, and then child pages within the section. It doesn’t support grandchild or deeper navigation.

The code is laid out in a really simple way, so you can see exactly how it works. Just place the following code in your QWordPress template functions.php file:

function get_breadcrumb() {
global $wp_query;
echo(‘<a href=”‘);
bloginfo(‘siteurl’);
echo(‘”>Home</a>’);
if(!is_home()) {
echo(‘ &raquo; ‘);
if (!empty($wp_query->post->post_parent) ) {
$parent = $wp_query->post->post_parent;
echo(‘<a href=”‘);
echo(get_permalink($parent));
echo(‘”> ‘);
echo(get_the_title($parent));
echo(‘</a> &raquo; ‘);
}
}
echo(‘<a href=”‘);
get_permalink();
echo(‘”>’);
the_title();
echo(‘</a>’);
}

To generate the breadcrumbs, just use

get_breadcrumb();

within any of the php files for your template.

Related Post

WordPress PHP code for sidebar with dynamic content determined by current page

Here is some really simple PHP code that I wrote for a client's WordPress site.…

Educate and inform instead of interrupt and sell

A great blog post by David Meerman Scott summarises why you should care about content…

10,000 Twitter Followers for just £99

I recently received an offer by email of “10,000 Twitter Followers for just £99”. Oh…