[Resolved] Remove category description on page 2, 3 etc

Home Forums Support [Resolved] Remove category description on page 2, 3 etc

Home Forums Support Remove category description on page 2, 3 etc

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #546968
    Gian

    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!

    #547434
    Leo
    Staff
    Customer Support

    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.

    #547451
    Gian

    Hi Leo, it worked!

    Thank you for your help!

    #547458
    Leo
    Staff
    Customer Support

    No problem ๐Ÿ™‚

    #1618200
    David

    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?

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.