Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Post-nav links

  • Hi,

    How can I remove a specific post category from the following rule:

    add_action( ‘after_setup_theme’, ‘tu_category_specific_post_navigation’ );
    function tu_category_specific_post_navigation() {
    add_filter( ‘generate_category_post_navigation’, ‘__return_true’ );
    }

    Thanks for your help,

    Philippe

  • Hi there,

    Try this:

    add_action('wp', 'custom_generate_category_post_navigation');
    function custom_generate_category_post_navigation() {
    	 if ( !in_category('cat-x')) {
    	    add_filter('generate_category_post_navigation', '__return_true' );
       }
    }

    Replace the cat-x with your category slug: https://codex.wordpress.org/Conditional_Tags#A_Category_Page

    Let me know if this helps 🙂

  • Hi Leo,

    I replaced cat-x with ‘articles’ (the concerned post category) but it does not work.

  • Hi there,

    Try this snippet:

    add_action('after_setup_theme', function() {
        add_filter('generate_category_post_navigation', function($display) {
            // List of category slugs to exclude
            $excluded_slugs = ['articles'];
    
            // Get the current post's category slugs
            $post_categories = get_the_category();
            $post_slugs = wp_list_pluck($post_categories, 'slug');
    
            // Check if the current post is in any of the excluded categories
            $is_excluded = !empty(array_intersect($excluded_slugs, $post_slugs));
    
            // If the post is in an excluded category, return false to disable navigation
            // Otherwise, return the original value
            return $is_excluded ? false : $display;
        });
    });
  • philipperoussel

    Hi Alvin,

    I did the following. It still does not work. No big deal if that cannot be achieved.

    add_action( ‘after_setup_theme’, ‘tu_category_specific_post_navigation’ );
    function tu_category_specific_post_navigation() {
    add_filter( ‘generate_category_post_navigation’, ‘__return_true’ );
    $excluded_slugs = [‘articles’];
    }

  • Hi there,

    can you share a link to a single post where the navigation needs to be removed ?

  • philipperoussel

    Hi David,

    This one, for instance: https://onehomeplanet.com/the-end-of-zionism/

  • Have you tried adding the entire snippet I provided above?

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