Modify Breadcrumb URL-Category Page Redirect

#56813
  • Resolved Evan
    Rank Math free

    Hi,

    I am using Rank Math breadcrumbs, however I need to have the category URL within the breadcrumb point to a different page than what is the default.

    I have my category pages redirecting to custom pages. For example, “/category/tools” is redirecting to a custom page with the url “/tools”. The default category breadcrumb URLs all point to “/category/tools” while I would like to point them directly to “/tools”.

    I see that this page may be able to help me change the URLs, although I don’t know how to do it: https://rankmath.com/kb/filters-hooks-api-developer/#change-remove-breadcrumb-items

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math today.

    The default category breadcrumb URLs all point to “/category/tools” while I would like to point them directly to “/tools”.

    Let me know if I understand you correctly, you wish to change your breadcrumbs from this “/category/tools” to this “/tools” If so, you can make sure the option to show categories in breadcrumbs settings is disabled: https://i.rankmath.com/0ovEMc

    You can also use the following function.

    /**
     * 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 ) {
            // check if we are viewing single posts
    	if(is_singular('post')){	
    		//Unset elements with key 1
    		unset($crumbs[1]);
                    $crumbs = array_values($crumbs);
    		return $crumbs; 
    	}
    	return $crumbs;
    }, 10, 2);

    Looking forward to helping you. Thank 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 1 replies (of 1 total)

The ticket ‘Modify Breadcrumb URL-Category Page Redirect’ is closed to new replies.