• I need to add the name of the page to the Breadcrumbs so that they show as Home–Contact Us, not Home–Page

Viewing 1 replies (of 1 total)
  • Hallo @raunhar, to add the current page name to the breadcrumbs in WordPress without using plugins, you can create a custom breadcrumb function. Here’s a concise way to do it: Step 1: Add Breadcrumb Function to Your Theme

    1. Edit your theme’s functions.php file and add the following function:

    Step 2: Add Breadcrumbs Code to Your Theme

    function custom_breadcrumbs() {
    // Settings
    $separator = ' » ';
    $home_title = 'Home';

    // Get the query & post information
    global $post;

    // Build the breadcrumbs
    echo '<ul id="breadcrumbs">';

    // Do not display on the homepage
    if ( !is_front_page() ) {

    // Home page
    echo '<li><a href="' . get_home_url() . '">' . $home_title . '</a></li>' . $separator;

    if ( is_single() || is_page() ) {
    // Standard page or single post
    echo '<li>' . get_the_title() . '</li>';
    } elseif ( is_category() ) {
    // Category page
    echo '<li>' . single_cat_title('', false) . '</li>';
    } elseif ( is_tag() ) {
    // Tag page
    echo '<li>' . single_tag_title('', false) . '</li>';
    } elseif ( is_day() ) {
    // Day archive
    echo '<li>' . get_the_time('Y') . '</li>' . $separator;
    echo '<li>' . get_the_time('F') . '</li>' . $separator;
    echo '<li>' . get_the_time('d') . '</li>';
    } elseif ( is_month() ) {
    // Month archive
    echo '<li>' . get_the_time('Y') . '</li>' . $separator;
    echo '<li>' . get_the_time('F') . '</li>';
    } elseif ( is_year() ) {
    // Year archive
    echo '<li>' . get_the_time('Y') . '</li>';
    } elseif ( is_author() ) {
    // Author archive
    echo '<li>' . get_the_author() . '</li>';
    } elseif ( get_query_var('paged') ) {
    // Paginated archives
    echo '<li>' . __('Page') . ' ' . get_query_var('paged') . '</li>';
    } elseif ( is_search() ) {
    // Search results page
    echo '<li>' . __('Search results for: ') . get_search_query() . '</li>';
    } elseif ( is_404() ) {
    // 404 page
    echo '<li>' . __('Error 404') . '</li>';
    }
    }
    echo '</ul>';
    }
    1. Edit your theme’s header.php, page.php, single.php, or wherever you want the breadcrumbs to appear.
    2. Add the following code where you want the breadcrumbs to be displayed:
    if ( function_exists('custom_breadcrumbs') ) {
    custom_breadcrumbs();
    }

    This setup will display breadcrumbs with the current page name, formatted as Home – Contact Us instead of Home – Page. The function covers various types of pages, including posts, categories, tags, archives, and more.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.