A quick post for WordPress users.
Go to your functions.php file. If it doesn’t exist, then create it.
wp-content/themes/theme_name/functions.php
Then add this inside the functions.php file.
function the_breadcrumb($post_ancestors) { if (!is_home()) { echo '<a href="'; echo get_option('home'); echo '">'; echo 'Home'; echo "</a> > "; if (is_category() || is_single()) { the_category('title_li='); if (is_single()) { echo " > "; the_title(); } } elseif (is_page()) { foreach($post_ancestors AS $value) { echo "<a href='".get_permalink($value)."'>".get_the_title($value)."</a> > "; } echo the_title(); } } } |
Then in your wp-content/themes/theme_name/index.php or anywhere in your template files, you can do this:
<?php global $post; ?> <div class="breadcrumbs"><?php the_breadcrumb(get_post_ancestors($post)); ?></div> |
That should display something like this:
Home > A Sample Page > Sub for the Sample Page
* Most of the source code is from here Catswhocode.com. I edited it so that you can get the “parents” for the pages. Thanks to for the kick-start!