Breadcrumb Navigation Link

#340065
  • Resolved Shivam Kumar
    Rank Math free

    Hi,

    I wanted to change my breadcrumb category link to the separate WordPress page that has the same URL except the word Category in it.

    (My current breadcrumb URL looks something like website.com/category/abc, and I want it to like to a separate pillar page website.com/abc)

    I am using the following code from one of your previous threads:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    //Adding to single posts
    global $post;
    if(is_singular('post')){
    //pass an array containing the name of the crumb, URL and
    //hide_in_schema option
    $catname = $crumbs[1][0];
    $subcatname = $crumbs[2][0];
    $value[] = array(
    $catname,
    'https://website.com/'.$catname,
    'hide_in_schema' => false
    );
    $newValue[] = array(
    $subcatname,
    'https://website.com/'.$catname.'/'.$subcatname,
    'hide_in_schema' => false
    );
    //add this value as the second item in array
    array_splice( $crumbs, 1, 1, $value );
    array_splice( $crumbs, 2, 1, $newValue );
    return $crumbs;
    }
    return $crumbs;
    }, 10, 2);

    The code is working well but the separator in the URL slug is missing (for example, URL slug appear as example page instead of example-page)

    Can you please modify the above code to include a separator (dash symbol) in the URL slug?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Prabhat
    Rank Math agency

    Hello,

    Thank you for contacting us.

    Assuming you’re referring to the URL of the breadcrumb category/sub-category item link, please try the below code and see if it gives you the desired output:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
        //Adding to single posts
        global $post;
        if(is_singular('post')){
            //pass an array containing the name of the crumb, URL and
            //hide_in_schema option
            $catname = $crumbs[1][0];
            $subcatname = $crumbs[2][0];
            $value[] = array(
                $catname,
                'https://website.com/'.str_replace(' ', '-', $catname),
                'hide_in_schema' => false
            );
            $newValue[] = array(
                $subcatname,
                'https://website.com/'.str_replace(' ', '-', $catname).'/'.str_replace(' ', '-', $subcatname),
                'hide_in_schema' => false
            );
            //add this value as the second item in array
            array_splice( $crumbs, 1, 1, $value );
            array_splice( $crumbs, 2, 1, $newValue );
            return $crumbs;
        }
        return $crumbs;
    }, 10, 2);

    Let us know how that goes.

    Thank you.

    Hello Prabhat, Your code worked but the trailing slash at the end of the URL is missing. Is there any way to fix that too?

    Prabhat
    Rank Math agency

    Hello,

    Please replace the previous code with the below one and let us know how that goes.

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
        //Adding to single posts
        global $post;
        if(is_singular('post')){
            //pass an array containing the name of the crumb, URL and
            //hide_in_schema option
            $catname = $crumbs[1][0];
            $subcatname = $crumbs[2][0];
            $value[] = array(
                $catname,
                'https://website.com/'.str_replace(' ', '-', $catname).'/',
                'hide_in_schema' => false
            );
            $newValue[] = array(
                $subcatname,
                'https://website.com/'.str_replace(' ', '-', $catname).'/'.str_replace(' ', '-', $subcatname).'/',
                'hide_in_schema' => false
            );
            //add this value as the second item in array
            array_splice( $crumbs, 1, 1, $value );
            array_splice( $crumbs, 2, 1, $newValue );
            return $crumbs;
        }
        return $crumbs;
    }, 10, 2);

    Looking forward to hearing back from you.

    Thank you.

    It worked Prabhat! Thank you for the quick response…

    Prabhat
    Rank Math agency

    Hello,

    We are super happy that we could address your concern. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind us asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

    Azib Yaqoob
    Rank Math business

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)

The ticket ‘Breadcrumb Navigation Link’ is closed to new replies.