-
philipperoussel
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_PageLet me know if this helps 🙂
-
philipperoussel
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/
-
Alvind
Have you tried adding the entire snippet I provided above?
- You must be logged in to reply to this topic.