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

10,000 Twitter Followers for just £99

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

Should AP use robots to write stories… or are earnings reports really that boring?

I was interested to see that the Associated Press (AP) plan to use software to…

Is social media all faked?

It's not unusual to hear complaints of companies engineering their social media presence, and I've…