Site logo

[Resolved] How to hide category or tag archives

Home Forums Support [Resolved] How to hide category or tag archives

Home Forums Support How to hide category or tag archives

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2421101
    Saini

    Hi, I want a customization under post category archives and tag archives. Actually, I am using Ninjatable plugin which is fetching my wordpress website posts along with relevant details and showing in a table like row wise. I am using that table id in a particular category description lets say “exercise” category. when the category is opened first the table is opening showing the posts as per my conditions specified in the table(as per exercise and other categories). But at the bottom of the table the posts included in that category i.e. “exercise” are being fetched. What I want is that I have to show majority of the categories posts in tables only and dont want to show the archives associated with those category. Is there any possible way to hide or disable the archives of categories and tags. I know its tricky.. Please help.

    Thank you

    #2421418
    David
    Staff
    Customer Support

    Hi there,

    GP archive templates has the generate_has_default_loop filter.
    And we can use it like so to remove the theme loop:

    
    add_filter( 'generate_has_default_loop', function($loop){
        if ( is_category( 'your_category' ) ) {
            $loop = false;
        }
        return $loop;
    } );

    However this also removes the entry title where the description is displayed, so you will need to hook that back in:

    
    add_action( 'wp', function() {
        add_action( 'generate_before_main_content', 'generate_archive_title' );
    });

    The codes above are PHP – this doc explains how to add that to your site:
    https://docs.generatepress.com/article/adding-php/

    #2421979
    Saini

    Thanks for replying david.

    I have installed the generate_has_default_loop code through code sinppets plugin and its running fine i.e. ‘your_category’ changed to ‘exercise’ category, and now the exercise category page is not showing archive title, description or any archives.

    However, when i tried to put this code

    <?php
    add_action( ‘wp’, function() {
    add_action( ‘generate_before_main_content’, ‘generate_archive_title’ );
    });
    ?>

    in Hook element and setting it to display on “exercise” category (Hook choosen: ‘generate_before_main_content’ and also “run on php” option ticked). It seems like the code is not working. No title, description is showing over that “exercise” category.

    I dont know whether I am missing something. Please help

    #2422086
    Ying
    Staff
    Customer Support

    Hi there,

    Both David’s PHP code needs to be added via the code snippet plugin.

    #2422489
    Saini

    Amazing fix!

    thanks David and Ying. You Guys r awesome..

    Cheers.

    0

    #2422802
    David
    Staff
    Customer Support

    Glad we could be of help!

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