Archived topic
Breadcrumbs + Rankmath
11 replies · Started by Stephan Bloemers on November 30, 2022
Hello,
i have a problem with the breadcrumbs and rankmath.
I use the Code Snippets plugin to insert the breadcrumbs. For this I use the following code:
add_action( 'generate_after_content', function() {
if ( function_exists('rank_math_the_breadcrumbs') ) {
rank_math_the_breadcrumbs( '<div class="grid-container grid-parent"><p id="breadcrumbs">','</p></div>' );
}
} );
Unfortunately then appears on page 2 of my blog:
Page 2
Page 3 then shows:
side
etc.
This is not displayed within my contribution (which is also correct), only on the overview

Hi there,
Have you considered creating an Element with a shortcode to add the breadcrumbs?
That way you can use the display rules to control where it shows and doesn't show.
Take a look at the instruction here:
https://docs.generatepress.com/article/adding-breadcrumbs/
Let me know if this helps :)
Thank you for the tip, that would of course work, but for certain reasons it is not possible for me in this specific case.
At first I thought there was a problem with rankmath, so I contacted them. I was advised the following:
You can get in touch with them and ask them to only restrict the preview for the content inside the entry-content div
So you just want to remove it from page 2 and so on?
If so you would need to include a conditional tag:
https://codex.wordpress.org/Conditional_Tags#A_Paged_Page
I may not seem to be expressing myself clearly. May be due to google translator.
At https://docs.generatepress.com/article/adding-breadcrumbs/ you specify how to insert breadcrumbs using a function. However, this will result in an error if the breadcrumbs are not inserted "after_header" but "after_content".
Everything is fine on the home page. If I continue to page 2 in the blog, the error shown in the picture appears.
I don't see any breadcrumbs on the home page (first page) - is that what you wanted?
Breadcrumbs are normally only added in single posts.
Let me know :)
You have to go to the second page
There is some miscommunications here for sure.
Let me rephrase the question: What is the expected result here?
Where would you like the breadcrumbs to display? Only on single posts?
Yes, the breadcrumbs should only be within the individual posts.
However, the page number "2" is also displayed on the "overview page".
Try this snippet instead:
add_action( 'generate_after_content', function() {
if ( function_exists('rank_math_the_breadcrumbs') && is_single() ) {
rank_math_the_breadcrumbs( '<div class="grid-container grid-parent"><p id="breadcrumbs">','</p></div>' );
}
} );
Thank you very much, that solves the problem.
And also thank you for your patience
No problem :)