Creating Breadcrumb Navigation in WordPress Themes

Posted on 21st June 2023

Breadcrumb navigation is a great way to improve the usability of your WordPress site. By providing users with an easy way to see where they are on your site, breadcrumb navigation can help reduce the number of clicks it takes to get to a particular page. In addition, breadcrumb navigation can also help search engines better index your site.

While breadcrumb navigation is not required on all WordPress sites, it is a good idea to include it on sites with a lot of content or pages. If you are developing a WordPress theme, there are a few different ways you can add breadcrumb navigation to your theme.

The easiest way to add breadcrumb navigation to your WordPress theme is to use a plugin. There are a number of different plugins available that will add breadcrumb navigation to your site.

If you are not using a plugin, you can still add breadcrumb navigation to your WordPress theme. To do this, you will need to edit your theme’s code.

The first thing you will need to do is add the following code to your theme’s header.php file:

<?php if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb('

‘); } ?>

This code will check to see if the Yoast SEO plugin is installed and activated. If it is, the breadcrumb navigation will be displayed. If the plugin is not installed or activated, the breadcrumb navigation will not be displayed.

Next, you will need to edit your theme’s style.css file. You will need to add the following CSS code to your file:

#breadcrumbs {
font-size: 12px;
font-weight: bold;
padding: 0px;
margin: 0px;
}

#breadcrumbs a {
color: #000000;
text-decoration: none;
}

#breadcrumbs span {
color: #333333;
}

This CSS code will style the breadcrumb navigation. You can change the CSS to match your theme’s style.

Finally, you will need to edit your theme’s footer.php file. You will need to add the following code to the file:

<?php if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb('

‘); } ?>

This code will check to see if the Yoast SEO plugin is installed and activated. If it is, the breadcrumb navigation will be displayed. If the plugin is not installed or activated, the breadcrumb navigation will not be displayed.

Adding breadcrumb navigation to your WordPress theme can improve the usability of your site. By providing users with an easy way to see where they are on your site, you can help reduce the number of clicks it takes to get to a particular page.

Breadcrumb navigation is a great way to improve the usability of your WordPress site. By providing users with an easy way to see where they are on your site, breadcrumb navigation can help reduce the number of clicks needed to reach a specific page.

There are a few different ways to add breadcrumb navigation to your WordPress site. In this article, we will show you how to add breadcrumb navigation to your WordPress theme.

What is Breadcrumb Navigation?

Breadcrumb navigation is a type of navigation that allows users to see their current location on a website. It is typically represented by a series of links, with the current page being the last link in the series.

For example, if a user is on the “About” page of a website, the breadcrumb navigation might look like this:

Home > About

If the user clicks on the “Home” link, they will be taken back to the home page. If the user clicks on the “About” link, they will be taken to the about page.

Why Use Breadcrumb Navigation?

Breadcrumb navigation is a great way to improve the usability of your website. By providing users with an easy way to see their current location on your site, breadcrumb navigation can help reduce the number of clicks needed to reach a specific page.

In addition, breadcrumb navigation can also help search engines understand the structure of your website. This can help improve your website’s search engine optimization (SEO).

How to Add Breadcrumb Navigation in WordPress

There are a few different ways to add breadcrumb navigation to your WordPress site. In this article, we will show you how to add breadcrumb navigation to your WordPress theme.

1. Install and Activate the Breadcrumb NavXT Plugin

The first thing you need to do is install and activate the Breadcrumb NavXT plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Settings ยป NavXT to configure the plugin settings.

On the plugin settings page, you need to select a breadcrumb separator. This is the character that will be used to separate the links in the breadcrumb navigation.

You can also choose to show the home page link, the blog page link, post category, and post tag in the breadcrumb navigation.

Once you are done, click on the Save Changes button to store your settings.

2. Add Breadcrumb Navigation in WordPress Theme

The next thing you need to do is edit your WordPress theme files and add the following code to your theme’s template files where you want the breadcrumb navigation to appear.

That’s it. You have successfully added breadcrumb navigation to your WordPress site.

We hope this article helped you learn how to add breadcrumb navigation in WordPress. You may also want to check out our guide on how to improve your WordPress SEO for beginners.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Breadcrumbs are an important part of any website, but they are often overlooked. By adding breadcrumb navigation to your WordPress theme, you can make it easier for users to navigate your site and find what they are looking for.

There are a few different ways to add breadcrumb navigation to your WordPress theme. You can use a plugin, or you can add the code yourself.

If you want to add breadcrumb navigation to your WordPress theme yourself, you will need to edit your theme files. The easiest way to do this is to use a child theme. This way, you can make changes to your theme without affecting the original files.

Once you have created a child theme, you can add the following code to your functions.php file:

function breadcrumbs() {

$showOnHome = 0; // 1 – show breadcrumbs on the homepage, 0 – don’t show
$delimiter = ‘»’; // delimiter between crumbs
$home = ‘Home’; // text for the ‘Home’ link
$showCurrent = 1; // 1 – show current post/page title in breadcrumbs, 0 – don’t show
$before = ‘‘; // tag before the current crumb
$after = ‘
‘; // tag after the current crumb

global $post;
$homeLink = get_bloginfo(‘url’) . ‘/’;

if (is_home() || is_front_page()) {

if ($showOnHome == 1) echo ‘

‘;

} else {

echo ‘

‘ . $home . ‘ ‘ . $delimiter . ‘ ‘;

if ( is_category() ) {
$thisCat = get_category(get_query_var(‘cat’), false);
if ($thisCat->parent != 0) echo get_category_parents($thisCat->parent, TRUE, ‘ ‘ . $delimiter . ‘ ‘);
echo $before . ‘Archive by category “‘ . single_cat_title(”, false) . ‘”‘ . $after;

} elseif ( is_search() ) {
echo $before . ‘Search results for “‘ . get_search_query() . ‘”‘ . $after;

} elseif ( is_day() ) {
echo ‘‘ . get_the_time(‘Y’) . ‘ ‘ . $delimiter . ‘ ‘;
echo ‘‘ . get_the_time(‘F’) . ‘ ‘ . $delimiter . ‘ ‘;
echo $before . get_the_time(‘d’) . $after;

} elseif ( is_month() ) {
echo ‘‘ . get_the_time(‘Y’) . ‘ ‘ . $delimiter . ‘ ‘;
echo $before . get_the_time(‘F’) . $after;

} elseif ( is_year() ) {
echo $before . get_the_time(‘Y’) . $after;

} elseif ( is_single() && !is_attachment() ) {
if ( get_post_type() != ‘post’ ) {
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
echo ‘‘ . $post_type->labels->singular_name . ‘‘;
if ($showCurrent == 1) echo ‘ ‘ . $delimiter . ‘ ‘ . $before . get_the_title() . $after;
} else {
$cat = get_the_category(); $cat = $cat[0];
$cats = get_category_parents($cat, TRUE, ‘ ‘ . $delimiter . ‘ ‘);
if ($showCurrent == 0) $cats = preg_replace(“#^(.+)s$delimiters$#”, “$1”, $cats);
echo $cats;
if ($showCurrent == 1) echo $before . get_the_title() . $after;
}

} elseif ( !is_single() && !is_page() && get_post_type() != ‘post’ && !is_404() ) {
$post_type = get_post_type_object(get_post_type());
echo $before . $post_type->labels->singular_name . $after;

} elseif ( is_attachment() ) {
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID); $cat = $cat[0];
echo get_category_parents($cat, TRUE, ‘ ‘ . $delimiter . ‘ ‘);
echo ‘‘ . $parent->post_title . ‘‘;
if ($showCurrent == 1) echo ‘ ‘ . $delimiter . ‘ ‘ . $before . get_the_title() . $after;

} elseif ( is_page() && !$post->post_parent ) {
if ($showCurrent == 1) echo $before . get_the_title() . $after;

} elseif ( is_page() && $post->post_parent ) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = ‘ID) . ‘”>’ . get_the_title($page->ID) . ‘‘;
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
for ($i = 0; $i display_name . $after;

} elseif ( is_404() ) {
echo $before . ‘Error 404’ . $after;
}

if ( get_query_var(‘paged’) ) {
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ‘ (‘;
echo __(‘Page’) . ‘ ‘ . get_query_var(‘paged’);
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ‘)’;
}

echo ‘

‘;

}
} // end breadcrumbs()

?>