nemrod.se Various guides and experiments

Breadcrumb function with heading structure for WordPress [PHP]


My coworker wanted breadcrumbs where the ancestry went from h1 all the way down to as deep as you are for one of our clients’ website, and so I wrote this little function for him:

<?php
    function hawt_breadcrumb() {
        global $post;

        $pages = array();

        $pages[] = array(get_permalink(), get_the_title());

        $parent = $post->post_parent;
        while($parent) {
            $pages[] = array(get_permalink($parent), get_the_title($parent));
            $parent = get_post($parent)->post_parent;
        }   

        $i = 1;
        foreach(array_reverse($pages) as $page) {
            echo "<h$i>$page[1]</h$i>";
            $i++;
        }   
    }   
?>

Might as well share it in case someone is in the need of something similar. :)


Posted in WordPress | 2 Comments

2 responses to “Breadcrumb function with heading structure for WordPress [PHP]”

  1. kos says:

    very nice!

    I wonder how many WP developers can make it in just a few lines as well lol! I guess not many ;)

    bookmarking this page, I have a feeling it might come handy sometime!

    :)

  2. […] using the permalink on my blog and it shows up just fine on Facebook. That's me liking this post. I'm using the iframe code though, more precisely this here: HTML […]

Leave a Reply

Your email address will not be published. Required fields are marked *