Site logo

Archived topic

Adjustment of column number in CPT archive applied to general post archive

3 replies · Started by Jens on March 2, 2023

Viewing posts 1–4 of 4

I have used a code from the help forum to adjust the number of columns of a custom post types ("template"). This worked. I now see 4 columns in the respective archive. Unfortunately the number of columns in the general post archive (set to 3 in customizer in Generatepress theme) has also changed to 4. How can I ensure that the 4 columns is only applied to the CPT?

add_filter( 'generate_blog_columns','tu_portfolio_columns' );
function tu_portfolio_columns( $columns ) {
    if ( is_post_type_archive( 'template' ) ) {
        return true;
    }

    return $columns;
}

add_filter( 'generate_blog_get_column_count', function( $column_width ) {
    if ( is_archive ('template') ) {
        return '25';
    }

    return $column_width;
} );

Thanks in advance!

Hi there,

thats odd, what if you use the is_post_type_archive( 'template' ) template tag in the second function ie.

add_filter( 'generate_blog_get_column_count', function( $column_width ) {
    if ( is_post_type_archive( 'template' ) ) {
        return '25';
    }

    return $column_width;
} );

Thanks a lot! That did the trick :-)

Glad to hear that!

This archived topic is closed to new replies.