Change breadcrumb trail from Home>Category>Title to Home>Blog>Category>Title

#17121
  • Resolved Henry Obilor
    Rank Math free

    We need to change the breadcrumb trail on posts (not pages) from what it is now

    Home>Category>Title

    to

    Home>Blog>Category>Title

    Here is an example where its used Site example

Viewing 8 replies - 1 through 8 (of 8 total)
  • just wrote this. Should work in your case.

    
    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    
    	if ( is_singular('post') ) {
    		
    		$insert = [
    			0 => __('Blog', 'text-domain'),
    			1 => get_permalink( get_option( 'page_for_posts' ) ), // if your home page is the blog url use 1 => get_home_url()
    			'hide_in_schema' => false
    		];
    		array_splice( $crumbs, 1, 0, $insert );
    			
    	}
    
    }
    

    I added the code.. It refused saving.. It read “Your PHP code changes were rolled back due to an error on line 0 of file Unknown. Please fix and try saving again.

    Exception thrown without a stack frame”

    @whytetips which file did you try to edit and did you miss the <?php at the start of the file?

    I pasted the code you gave me.. theres no ‘<?php’ in the code
    and i added the code via functions.php

    As you said it reports an error on line 0 of your file. Did you paste the code before or after the starting <?php?

    This is what i pasted
    <?php
    add_filter( ‘rank_math/frontend/breadcrumb/items’, function( $crumbs, $class ) {

    if ( is_singular(‘post’) ) {

    $insert = [
    0 => __(‘Blog’, ‘text-domain’),
    1 => get_permalink( get_option( ‘page_for_posts’ ) ), // if your home page is the blog url use 1 => get_home_url()
    ‘hide_in_schema’ => false
    ];
    array_splice( $crumbs, 1, 0, $insert );

    }

    }

    I pasted this code at ‘functions.php in ‘Generatepress child theme’

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    
    	if ( is_singular('post') ) {
    		
    		$insert = [
    			0 => __('Blog', 'text-domain'),
    			1 => get_permalink( get_option( 'page_for_posts' ) ), // if your home page is the blog url use 1 => get_home_url()
    			'hide_in_schema' => false
    		];
    		array_splice( $crumbs, 1, 0, $insert );
    			
    	}
    
    }, 10, 2);

    sorry missed closing the function. Now it’s working.

    The code saved but it removes the breadcrumb completely from my blog post

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

The ticket ‘Change breadcrumb trail from Home>Category>Title to Home>Blog>Category>Title’ is closed to new replies.