Add a breadcrumb trail to a WordPress site? Sounds like it was a matter of switching one option. Not in WordPress!
What I realized, adding a breadcrumb required four actions:
- Install a breadcrumb plugin.
- Create a child theme if you use a stock theme.
- Edit theme file to display the breadcrumb in a correct position.
- Edit theme file to style the theme.
Table of contents
Install a breadcrumb plugin
I have tried two plugins: Breadcrumb and Breadcrumb NavXT.
The Breadcrumb plugin seemed to be simpler in use. It automatically displayed the breadcrumb in the page’s header. But the effect was miserable. I was not able to change some options. I was not able to change its theme to plain text. And it displayed “Home > 02” as breadcrumb trail in a blog post. I uninstalled this plugin because fixing it would be probably too complex.
E-book: How to set up free WordPress platform for IT blogs
Do you want to set up a typical blog but you don’t know how to start, which plugins to use or how to customize the site? I spent a few weeks in total doing that from scratch – from learning the ecosystem to adjusting the platform to my very specific needs. Now I want to share with my experience and make the start easier for you.
Another plugin is Breadcrumb NavXT and it’s the most popular one. The problem with this one is that it does not render the breadcrumb on the page. I could only add a widget to a sidebar with the breadcrumb, which is not the right location for it.
I learned I can display the breadcrumb by calling a PHP function in my theme. It will be described in the next steps.
In the plugin’s settings I have enabled the home breadcrumb in the trail and changed the name of “home” in the breadcrumb from my site’s name to “Home”:
Create a child theme
This step can be skipped for quick experiments.
A child theme is a theme that inherits from your base stock theme and which enables you to modify it slightly while allowing to maintain the base theme. If you edited directly the stock theme’s files, your changes would be probably overwritten during next upgrade of the theme.
Although the steps to create a child theme are not complicated, they require many more skills than clicking options in WordPress administration pages.
Head to WordPress – I created a child theme, but it looks different because of Bootstrap for more details on how to create a child theme in WordPress.
Edit theme file
In my case it was enough to add a line to Theme Header (header.php):
If that file does not exist in the child theme, it should be copied from the base theme.
bcn_display will call Breadcrumb NavXT‘s plugin method to render the breadcrumb.
Style the breadcrumb
Although the breadcrumb should be visible by now, it won’t look good. Adding some margins should be enough to make it decent.
First I have put the breadcrumb in the same container as the rest of the content is in. One option would be to modify several files (post, search, main), the other option is to edit the same Theme Header (header.php) file and write:
This code adds some divs to mimic the contents’ section structure (I copied that from the beginning of Single Page (page.php) file). The first and last lines (
endif) hide the breadcrumb from the home page.
I added some margin at the bottom and hid the filters (“Browsed By”) in the theme’s style Stylesheet (style.css) as it was duplicating the breadcrumb: