Page slug and Category slug > Adjust breadcrumb

#88117
  • Resolved Marketence Service
    Rank Math business

    Hi,

    Iā€™m creating a silo structure on my new site and i have a problem.
    I had created 2 url below with the same slug:

    1: mydomain.com/abc/key-word/ => this is a page
    2: mydomain.com/category/abc/key-word/ => this is a category

    When I use the breadcrumb feature; there is a breadcrumb inserted in my page like

    home >> abc >> key-word

    Linking to home, /abc and /abc/key-word

    On my blog message, there is a breadcrumb inserted like this:

    home >> abc >> key-word

    Linking to home, /category/abc and /category/abc/key-word

    However, I want the breadcrum in the blogmessage linked to the URL’s of the pages, so without the /category option.

    If I strip the “category” under “general > strip category base” then when they click the breadcrumb link, wordpress will load the blog category messages, but that’s not what I want. I want it to load the page.

    Is there a way to get around this? I’ve searched for hours.. šŸ™

    Hans

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for getting in touch with us.

    You can use the following function to modify your breadcrumb items You can choose to create a linked label which can contain the URL of the page you want the crumb item to link to:

    
    /**
     * Allow changing or removing the Breadcrumb items
     *
     * @param array       $crumbs The crumbs array.
     * @param Breadcrumbs $this   Current breadcrumb object.
     */
    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    	return $crumbs;
    }, 10, 2);
    

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Hi,

    Thanks for your reply!

    I think I understand a bit what you want to do, but only so much. Can you explain in a bit more detail which file I have to edit and where I can create a linked label?

    Hans

    Hello,

    This code added in your functions.php file. Below is a sample code, you will need to customize it to fit your intent.

    /**
     * This is an example to remove the second item in your post breadcrumbs
     * Allow changing or removing the Breadcrumb items
     *
     * @param array       $crumbs The crumbs array.
     * @param Breadcrumbs $this   Current breadcrumb object.
     */
    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
               $modifiedCrumb = array(
    		"0"=>esc_html('someLabel'),
    		"1"=>esc_url('/url-to-category/'), // Modify this with the URL you want
    		"hide_in_scheme"=>false
    	    );  
                $crumbs[1] = $modifiedCrumb;
    
    	return $crumbs;
    }, 10, 2);

    Please note that we don’t usually provided customized solutions and you might have to hire a developer to assist you with this if you aren’t one.

    Hope this helps you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘Page slug and Category slug > Adjust breadcrumb’ is closed to new replies.