Wordpress Breadcrumbs

01 January 2004

This PhP script implements a breadcrumbs menu (see example below), which should work out of the box with Wordpress.

Example of breadcrumbs

 * quick and dirty breadcrumb menu
 * initially designed for wordpress
function CPbreadcrumbs() {
    $CPtheFullUrl = $_SERVER["REQUEST_URI"];
    echo '<a href="/">Home</a>';
    while (list($CPj,$CPtext) = each($CPurlArray)) {
        if ($CPj > 1) {
            while ($CPi < $CPj) {
                $CPdir .= '/' . $CPurlArray[$CPi];
                $CPtext = $CPurlArray[$CPi];
            if($CPj < count($CPurlArray)-1) echo ' &raquo; <a href="'.$CPdir.'">' . str_replace("-", " ", $CPtext) . '</a>';
    echo wp_title();

To use it, just put that block of code into your Wordpress file where you want the menu to appear.

If you don’t use Wordpress but still want to use this, you may have to change REQUEST_URI at the start of the script to PHP_SELF. And then at the bottom, change wp_title() to be a function that gives the title of the current page.