Site logo

Archived topic

Conditional function for Yoast breadcrumbs in static page archives

0 replies · Started by George on March 19, 2021

Viewing posts 1–1 of 1

I am following this article trying to add Yoast breadcrumbs for category pages.
https://docs.generatepress.com/article/adding-breadcrumbs/


add_action( 'generate_before_main_content', function() {
    if ( function_exists('yoast_breadcrumb') && is_category() ) {
        yoast_breadcrumb( '<div class="grid-container grid-parent"><p id="breadcrumbs">','</p></div>' );
    }
} );

I know that normally it should work but at the same time, I am using the following code from this article to create static pages as category archives.


add_filter('request', function( array $query_vars ) {
    if ( is_admin() ) {
        return $query_vars;
    }

    if ( isset( $query_vars['category_name'] ) ) {
        $pagename = $query_vars['category_name'];

        $query_vars = array( 'pagename' => "$pagename" );
    }

    return $query_vars;
} );

At the same time, I would like to use a function instead of a conditional hook. The code will not work though, probably because it can't find the original category archives.

There are around 12 categories. Is there a PHP trick I could use to select those static category archives without selecting page IDs (Just want it to be future-proof)?

This archived topic is closed to new replies.