Add Breadcrumbs to WordPress Without a Plugin
Breadcrumbs are a great way to give people a perspective of where they are on your site. You can easily add them via several good plugins (my favorite is Yoast Breadcrumbs), but sometimes you want to build breadcrumbs into a theme without using a plugin, especially if you’re releasing it to the public. This was what I needed to do with my latest latest WordPress theme. So here’s what I did…
1. I created a php file called breadcrumbs.php and inserted the following code…
-
-
<div class="breadcrumbs">
-
-
<?php
-
-
function breadcrumbs() {
-
$theFullUrl = $_SERVER["REQUEST_URI"];
-
echo ‘You Are Here: <a href="/">Home</a>’;
-
$dir=”;
-
if ($j > 1) {
-
$i=1;
-
while ($i < $j) {
-
$dir .= ‘/’ . $urlArray[$i];
-
$text = $urlArray[$i];
-
$i++;
-
}
-
if($j < count($urlArray)-1) echo ‘ » <a href="’.$dir.‘">’ . str_replace("-", " ", $text) . ‘</a>’;
-
}
-
}
-
}
-
breadcrumbs();
-
?>
-
-
</div><!–/breadcrumbs–>
-
Notice that I’ve included an opening and closing div with the pseudoclass of “breadcrumbs” so that I can add some style to the stylesheet.
2. Wherever I want to include the breadcrumbs in my theme files, I add this line…
-
-
<?php include ( TEMPLATEPATH . ‘/breadcrumbs.php’); ?>
-
That’s it! You can do the same by creating a function in your functions file and then calling the function in your theme, but I think this may be the most simple way to reach the objective.
Want to customize it a bit? Notice that I’ve “echoed” the phrase “You Are Here:” but you can change that text to whatever you’d like to lead the breadcrumb trail. And you can also change the “»” near the bottom to a “|” or “/” or whatever you like. Then you can style your breadcrumbs in the stylesheet.
There are probably better ways, but this is my way. Enjoy.

Wow, this is what I was searching for so long! I always try to avoid the use of another plugin. So this is a great snippet of script. Thanx!!!
Thanks so much, this is a great little script. Basing breadcrumbs on urls is brilliantly logical. Thanks again.
Your breadcrumb script really is far more elegant than installing a Wordpress plugin, and more durable too. After working out a few “single quote” issues from the copy and past, the snippet worked perfectly!
Thanks so much for sharing it.
Marj Wyatt aka Virtually Marj
Glad it worked for you – thanks so much!