How to make WordPress breadcrumbs nav menu

Breadcrumbs is the most useful element for any website to show the location or follow of the page, in this post we will learn how to generate breadcrumbs in wordpress. now start step by step

Breadcrumb

Breadcrumb

first

Open your functions.php file and make a function for getting the breadcumb menu

example

function hm_get_breadcrumb() {    }

Second

Now in the begining of the function print ul and at the end of the function print the end tag of ul

example

function hm_get_breadcrumb() { echo '<ul>'; echo '</ul>'; }

Third

now inside the ul get the homepage link and location should be in first as in case of a website the first viewing page is home

Example

function hm_get_breadcrumb() { echo '<ul><li><a href="'.home_url().'" rel="nofollow">Home</a></li>'; echo '</ul>'; }

Fourth

Now get the page link and location if category or if page or if search

Example
<?php

function hm_get_breadcrumb() {

echo '<ul><li><a href="'.home_url().'" rel="nofollow">Home</a></li>';

if (is_category() || is_single()) {

echo "<li><a>&#187;</a></li>";

the_category(' &bull; ');

if (is_single()) {

echo "<li><a>&#187;</a></li>";

echo "<li><a>";

the_title();

echo "</a></li>";

}

} else if (is_page()) {

echo "<li><a>&#187;</a></li>";

echo "<li><a>";

echo the_title();

echo "</a></li>";

} elseif (is_search()) {

echo "<li><a>&#187;</a></li>";

echo "<li><a>";

echo '"<em>';

echo the_search_query();

echo '</em>"';

echo "</a></li>";

}

echo '</ul>';

}

?>

and it is the total function also
Fifthnow call the function from where you want to shoe the breadcrumbs

example

<?php hm_get_breadcrumb(); ?>

And the breadcrumbs will show at the position you want to shoe the breadcrumbs and to change the design write some css code.

Thanks for reading

Share The Post On -