Customization of Breadcrumbs

#156106
  • Resolved Daniel
    Rank Math free

    Hi, I need some help for the breadcrumbs. I understand that I have to paste in the [rank_math_breadcrumb] shortcode into my post. I also know I have to add to paste in custom code snippet into my theme’s functions.php file if I want to customize the breadcrumbs.

    Here are my questions.

    1) Currently the breadcrumbs is like ‘Home >> Parent Category >> My Post’.
    I want the path to become:
    ‘Home >> Static Page A >> My Post’, such that the URL is changed to Static Page A’s URL too.

    2) Similarly with reference to point 1, for current breadcrumbs like ‘Home >> Parent Category >> Sub Category >> My Post’.
    I want the path to become:
    ‘Home >> Static Page A >> Static Page B >> My Post’, such that the URL is changed to Static Page A and Static Page B respectively.

    3) Are the above 2 points achievable? Do I need to create different shortcodes other than the standard [rank_math_breadcrumb]? Because different posts may have different paths.

    In this case I may need something like the array_splice function? Would really appreciate if you can help to provide the entire code snippet. Thank you!

    Regards,
    Daniel

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

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for the delay.

    You can use and customize our filter to customize your breadcrumbs:
    https://rankmath.com/kb/filters-hooks-api-developer/#change-remove-breadcrumb-items

    Here is an example of customizing the breadcrumbs on how to add a crumb to the trail using the array_splice() function:

    
    /**
     * 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 ) {
            //Adding to single posts
    	if(is_singular('post')){
                    //pass an array containing the name of the crumb, URL and 
                    //hide_in_schema option	
                    $value[] = array(
    		'Custom Page', 
                    'http://localhost/rankmath', 
                    'hide_in_schema' => false
    		);
                    //add this value as the second item in array
    		array_splice( $crumbs, 1, 0, $value ); 
    		return $crumbs; 
    	}
    	return $crumbs;
    }, 10, 2);
    

    I hope that helps. Thank you, and please don’t hesitate to contact us if you need further assistance.

    Daniel
    Rank Math free

    Hi Reinelle, thanks for your response.

    Unfortunately I’m not a web developer so I do not quite understand what do I need to remove and how do I add in the codes for my requirement.

    1) So if I want to remove the original Parent Category and its URL, what code should I remove?

    2) And to add in Static Page A (for example http://mydomain.com/static-page-A) and Static Page B (for example http://mydomain.com/static-page-B), what codes should I add in?

    Would really appreciate if you can help to show the exact coding. Thanks!

    Regards,
    Daniel

    Hello,

    I am afraid we do not offer code customization, we usually share a guide with which you can use and create you final custom code.

    You may have to hire a developer to assist you in this and get in touch with is if further guidance is needed.

    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 3 replies - 1 through 3 (of 3 total)

The ticket ‘Customization of Breadcrumbs’ is closed to new replies.