Site logo

Archived topic

When to call add_filters?

3 replies · Started by Anthony on August 8, 2017

Viewing posts 1–4 of 4

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/

Hmm just tested the code and it's working for me.

How are you adding it currently?

This archived topic is closed to new replies.