remove_action conditionally for Custom Post Type - not working

I'm using a Genesis child theme with the 'Genesis Co-Authors Plus' which enables support for Co-Authors Plus

I'd like to disable the author box everywhere except for the blog.

Genesis Co-Authors Plus removes the default Genesis genesis_do_author_box_single and replaces it with gcap_author_box

So far I've got a conditional function to remove gcap_author_box from the custom post type local-bite

I tested the conditional statement with a simple echo and it is working fine. So what is wrong with the following?:

// Remove 'Genesis Co-Authors Plus' from custom post type
add_action('init', 'lf_remove_author_box');
function lf_remove_author_box() {
    if ( is_singular( 'local-bite' ) ): {
        remove_action( 'genesis_after_entry', 'gcap_author_box', 8 );
    }
    endif;
}

There is a very similar post here which is helpful.

but I don't understand what I need to put in immediately after add_action - I've copied what is in the Genesis Co-Authors Plus which is init. I've also tried wp, can anyone help?

Topic genesis-theme-framework filters Wordpress

Category Web


I got it working in the end by using 'template_redirect' and changing the remove_action number from 8 to 1 :)

// Remove 'Genesis Co-Authors Plus' author box and 'filed under' from custom post type
add_action('template_redirect', 'lf_custom_cpt_display');
function lf_custom_cpt_display() {
    if ( is_singular( 'local-bite' ) ): {
        remove_action( 'genesis_after_entry', 'gcap_author_box', 1 );
        remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );
        remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
        remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );
    }
    endif;
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.