how to add custom breadcrumbs in wordpress?

admin2025-01-07  3

I need a custom breadcrumb for my account page.Can we do it via functions.php ?

add_filter('theme_breadcrumb_args_filter', 'customize_separator_breadcrumbs');

    function customize_separator_breadcrumbs($args) {
        $args['sep'] = ' >> ';
        return $args;
    }

I need a custom breadcrumb for my account page.Can we do it via functions.php ?

add_filter('theme_breadcrumb_args_filter', 'customize_separator_breadcrumbs');

    function customize_separator_breadcrumbs($args) {
        $args['sep'] = ' >> ';
        return $args;
    }
Share Improve this question edited Jul 22, 2019 at 11:10 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Jul 18, 2019 at 12:51 Pranav PatelPranav Patel 211 gold badge1 silver badge4 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

We’ve created a custom function called get_breadcrumb() to generate the breadcrumb links. You only need to add the get_breadcrumb() function code in functions.php file of the current theme.

function get_breadcrumb() {
    echo '<a href="'.home_url().'" rel="nofollow">Home</a>';
    if (is_category() || is_single()) {
        echo "&nbsp;&nbsp;&#187;&nbsp;&nbsp;";
        the_category(' &bull; ');
            if (is_single()) {
                echo " &nbsp;&nbsp;&#187;&nbsp;&nbsp; ";
                the_title();
            }
    } elseif (is_page()) {
        echo "&nbsp;&nbsp;&#187;&nbsp;&nbsp;";
        echo the_title();
    } elseif (is_search()) {
        echo "&nbsp;&nbsp;&#187;&nbsp;&nbsp;Search Results for... ";
        echo '"<em>';
        echo the_search_query();
        echo '</em>"';
    }
}

Display Breadcrumbs:
Call the get_breadcrumb() function in single.php file and others files where you want to display the breadcrumbs on your WordPress site.

<div class="breadcrumb"><?php get_breadcrumb(); ?></div>

Styling Breadcrumbs:
This CSS helps to style the breadcrumbs links.

.breadcrumb {
    padding: 8px 15px;
    margin-bottom: 20px;
    list-style: none;
    background-color: #f5f5f5;
    border-radius: 4px;
}
.breadcrumb a {
    color: #428bca;
    text-decoration: none;
}

SEE ALSO A USEFULL ANSWERS. https://stackoverflow.com/questions/50893992/creating-breadcrumbs-without-a-plugin

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736256826a392.html

最新回复(0)