WordPress Breadcrumbs for Pages

Breadcrumbs are very useful navigation tools, especially for sites with multiple levels and more than a dozen pages.  While there are a few breadcrumb navigation plugins for WordPress, sometimes it’s a bit of an overkill when the job can be done with just a few lines of code.

The function below will insert a breadcrumb navigation for the pages in your WP site, and highlight the news/blog page when within that section, etc.

Usage:

  1. Copy the code below into your theme’s functions.php file.  If your theme doesn’t have one, create it.
  2. //breadcrumb function
    function rm_bread_crumbs() {
     global $post;
     $crumbs =     '<p><a href="'.get_option('home').'">Home</a>';
    
     //if the page has a parent add title and link of parent
     if($post->post_parent) {
     $crumbs .=     ' &raquo; <a href="'.get_permalink($post->post_parent).'">'.get_the_title($post->post_parent).'</a>';
     }
    
     // if it's not the front page of the site, but isn't the blog either
     if((!is_front_page()) && (is_page())) {
     $crumbs .=    ' &raquo; '.get_the_title($post->ID);
     }
    
     //if it's the news/blog home page or any type of archive
     if((is_home() ||(is_archive()))) {
     $crumbs .=    ' &raquo; '.get_the_title(get_option(page_for_posts));
     }
    
     //if it's a single news/blog post
     if(is_single()) {
     $crumbs .=     ' &raquo; <a href="'.get_permalink(get_option(page_for_posts)).'">'.get_the_title(get_option(page_for_posts)).'</a>';
     $crumbs .=    ' &raquo; '.get_the_title($post->ID);
     }
     $crumbs .=    '</p>'."\n";
     echo $crumbs;
    }
  3. Insert <?php rm_bread_crumbs(); ?> in your theme where ever you’d like the bread crumbs displayed.

WordPress HTML Cheat-sheet

I’m putting this little post together to help my clients on WordPress, and hopefully a few other folks out there when composing WordPress posts and pages.  Please comment below with questions/additions, as I’ll continue updating this post.

Audience:
This cheat-sheet is intended for users using the WordPress CMS, and would like to have a bit more control over the layout and formatting.  It is not a complete guide to HTML, rather is focused on HTML formatting for using the WordPress post and page functions.

Scope:
We will be reviewing how to better format content within the Visual and HTML tabs for WordPress pages and posts, relying on WP’s built in rich text editor, a few HTML snippets, and a basic synopsis of CSS styles as they are relevant. Things such as Doctype and <head> tags that are not editable from the editor will not be covered.

Continue reading