Site logo

Archived topic

Remove category description on page 2, 3 etc

4 replies · Started by Gianluca on April 10, 2018

Viewing posts 1–5 of 5

Hi Tom,

I would like to ask you how to remove category description on subpages of my categories, to avoid duplicate content issues.

I found this topics:
https://generatepress.com/forums/topic/custom-intro-for-each-category-archive-for-first-page-only/
https://generatepress.com/forums/topic/remove-category-page-description-from-category-subpages/

and this code https://gist.github.com/generatepress/cc2d8b578c8c3706dcefe68234ca5c9f but I can't figure out how to use it.

Basically, what I want to achieve is to have the description only on the first page of categories archive and remove it from page 2, 3 etc

Thank you in advance for your help!

Hi there,

Excellent researching :)

Try this snippet:

add_action( 'wp', 'tu_remove_paged_category_description' );
function tu_remove_paged_category_description() {
    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    if ( 1 !== $page ) {
        remove_action( 'generate_archive_title', 'generate_archive_title' );
        add_action( 'generate_archive_title', 'tu_custom_paged_archive_title' );
    }
}

function tu_custom_paged_archive_title() {
    ?>
    <header class="page-header">
        <h1 class="page-title">
            <?php the_archive_title(); ?>
        </h1>
    </header>
    <?php
}

With one of these methods here: https://docs.generatepress.com/article/adding-php/

Code Snippets is the easiest if you aren't using a child theme.

Hi Leo, it worked!

Thank you for your help!

No problem :)

Hi Leo,

What about if I am using an Elements Header on my Archive Category pages and showing the description.

But then the code above does not prevent the description from not showing on pages 2, 3, 4, ....

I can not use php in an Element header, so any ideas?

This archived topic is closed to new replies.