Change breadcrumbs individual items

#72074
  • Resolved Ignacio
    Rank Math free

    Hi there,
    I want to change a particular item on breadcrumbs.
    I use a page instead of a category, so i want to reflect that on breadcrumbs
    Instead of this: {Homepage / Homepage URL} » {Category Id#10 Title / Category Id#10 URL} » {Post Title}
    Show this: {Homepage / Homepage URL} » {Page Id#20 Title / Page Id#20 URL} » {Post Title}
    Its only for one particular category
    Any solution?
    Regards!

Viewing 4 replies - 1 through 4 (of 4 total)
  • For reference, this is how i do it in Yoast:

    add_filter( 'wpseo_breadcrumb_single_link' ,'wpseo_remove_breadcrumb_link', 10 ,2);
    function wpseo_remove_breadcrumb_link( $link_output , $link ){
        $text_to_remove = 'Category Name';
      
        if( $link['text'] == $text_to_remove ) {
          $link_output = '<a href="PAGE URL">TEXT</a>';
        }
        return $link_output;
    }
    Alberto
    Rank Math business

    Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    Meanwhile we usually can’t provide custom code to our users due to we are a small team, now I was able to migrate that code to work on Rank Math, could you check it?

    /**
     *
     * @param array       $crumbs The crumbs array.
     * @param Breadcrumbs $this   Current breadcrumb object.
     */
    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    	$ret = $crumbs;
            $count = 0;
            $modifiedCrumb = NULL;
            
            $text_to_remove = 'Category Name';
    
            foreach($crumbs as $crumb) {
                if($crumb["0"]==$text_to_remove){
                     $modifiedCrumb = array(
    				"0"=>esc_html('PAGE NAME'),
    				"1"=>esc_url('/PAGE URL'),
    				"hide_in_scheme"=>false
    			);  
                      break;
                }
                $count++;
            }
    
            if($modifiedCrumb!=NULL){
                $ret[$count] = $modifiedCrumb;
            }
    
    	return $ret;
    }, 10, 2);

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Thanks Alberto, it works perfect!

    • This reply was modified 4 years, 2 months ago by Ignacio.
    Alberto
    Rank Math business

    Hello Ignacio,

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

You must be logged in to reply to this ticket.