Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

By default, my theme is showing an author box below my posts. I am using a custom post type, and would like to remove this author box only on this post type. Here is how the theme is calling the author box:

add_action( 'wp_head', 'woo_author', 10 );

if ( ! function_exists( 'woo_author' ) ) {
function woo_author () {
    // Author box single post page
    if ( is_single() && get_option( 'woo_disable_post_author' ) != 'true' ) { add_action( 'woo_post_inside_after', 'woo_author_box', 10 ); }
    // Author box author page
    if ( is_author() ) { add_action( 'woo_loop_before', 'woo_author_box', 10 ); }
} // End woo_author()
}

Here is the function I have tried to remove the post author box from the wpseo_locations single posts, but it is not working:

add_action('init', 'kiwi_remove_post_author_box'); 

function kiwi_remove_post_author_box () {
    if (is_singular('wpseo_locations')  ) {
        remove_action( 'woo_post_inside_after', 'woo_author_box', 9 );
    }  
}

I have also tried:

add_action('init', 'kiwi_remove_post_author_box'); 

function kiwi_remove_post_author_box () {
    if ( 'wpseo_locations' == get_post_type() ) {
        remove_action( 'woo_post_inside_after', 'woo_author_box', 9 );
    }  
}

I cannot seem to get that box to go away. I know that there is a check box in the theme options panel that will make it go away globally, but I want it removed only for this post type. Any help would be greatly appreciated.

share|improve this question
    
the actions are added with priority of 10, but you try to remove actions with priority 99? –  Milo Dec 18 '13 at 1:08
    
@Milo - typo. Just made the edits. Priority 9 does not work. –  itrogers Dec 18 '13 at 1:14
    
they should be 10, to match the priority they were added on –  Milo Dec 18 '13 at 1:22

2 Answers 2

up vote 2 down vote accepted

Query variable only can be accessed after wp_query has been called. In you call, the get_post_type() function is actually returning an empty value. It should be working, if you change the hook to something which fires after wp_query is called.
So, You should use -

add_action('wp', 'kiwi_remove_post_author_box');

OR

add_action('template_redirect', 'kiwi_remove_post_author_box');

Also, hooks can removed with the same priority value the have been added on.
So final code it would be -

add_action('template_redirect', 'kiwi_remove_post_author_box');
function kiwi_remove_post_author_box()
{
    if( is_singular('wpseo_locations') )
        remove_action( 'woo_post_inside_after', 'woo_author_box', 10 );
}
share|improve this answer
    
Thank you and @Milo for the clarification on priority. Removing the action on the wp_head worked, however, I had to change the remove_action inside the function. Will post the final code. –  itrogers Dec 18 '13 at 17:41
    
Yes, you should be using the remove_action within you function 'kiwi_remove_post_author_box'. I will update so you can understand. –  Shazzad Dec 18 '13 at 23:11

Thanks to @Shazzad, I was able to come up with the final code that worked.

add_action('template_redirect', 'kiwi_remove_post_author_box'); 

function kiwi_remove_post_author_box () {
    if ( 'wpseo_locations' == get_post_type() ) {
        remove_action( 'wp_head', 'woo_author', 10 );
    }  
}

Notice how the remove_action has changed inside the function. As soon as I did this it worked. Does this mean that you cannot use hooks if they are inside another function, and being called conditionally?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.