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

#17121
  • Resolved Anonymous
    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)
  • Anonymous
    Rank Math free

    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 );
    			
    	}
    
    }
    
    Anonymous
    Rank Math free

    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”

    Anonymous
    Rank Math free

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

    Anonymous
    Rank Math free

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

    Anonymous
    Rank Math free

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

    Anonymous
    Rank Math free

    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’

    Anonymous
    Rank Math free
    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.

    • This reply was modified 5 years, 9 months ago by .
    • This reply was modified 5 years, 9 months ago by .
    • This reply was modified 5 years, 9 months ago by .
    Anonymous
    Rank Math free

    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.