Archived topic
When to call add_filters?
3 replies · Started by Anthony on August 8, 2017
Hello, I'm trying to remove author, date, category and tag from single posts (but keep them for archive pages).
I don't understand when to call the filters. I tried something like that but it doesn't work. I guess the after_setup_theme is not the right action. Can you help ? Thank you
/* Remove meta on single post */
add_action( 'after_setup_theme', 'remove_post_meta' );
function remove_post_meta() {
if ( is_singular( 'post') ) {
add_filter( 'generate_post_author', '__return_false' );
add_filter( 'generate_post_date', '__return_false' );
add_filter( 'generate_show_categories', '__return_false' );
add_filter( 'generate_show_tags', '__return_false' );
add_filter( 'generate_show_comments', '__return_false' );
}
}
Hi there,
Try this:
add_action( 'wp','tu_remove_blog_meta' );
function tu_remove_blog_meta() {
if ( is_single() ) {
add_filter( 'generate_post_date_output','__return_false' );
add_filter( 'generate_post_author_output','__return_false' );
add_filter( 'generate_category_list_output','__return_false' );
add_filter( 'generate_tag_list_output','__return_false' );
add_filter( 'generate_show_comments','__return_false' );
}
}
Adding PHP: https://docs.generatepress.com/article/adding-php/
Hi, I have the same problem and tryed to use this snippet above, but it didn't worked.
I searched google and found this solution
http://docs.layerswp.com/doc/how-to-turn-off-comments-or-reviews-on-single-posts-or-products/
Hmm just tested the code and it's working for me.
How are you adding it currently?