Best way to filter featured image text for a custom post type?

Regardless if you go the PHP or jQuery route, I suggest you set up your filters or enqueue your Javascript in the admin_head-post[-new].php or admin_print_scripts-post[-new].php hook. There you can be sure that the global variable $post_type is set, and can check whether it is slide. Since the post thumbnail code is called after these hooks, you can set up your filters in this hook and they will be executed. Something like this:

add_action( 'admin_head-post-new.php', 'wpse4270_add_filters_for_slide' );
add_action( 'admin_head-post.php', 'wpse4270_add_filters_for_slide' );
function wpse4270_add_filters_for_slide()
{
    if ( 'slide' == $GLOBALS['post_type'] ) {
        add_filter( 'admin_post_thumbnail_html', 'meteorslides_set_featured', 9999, 1 );
        add_filter( 'admin_post_thumbnail_html', 'meteorslides_remove_featured', 9999, 1 );
        add_filter( 'gettext', 'meteorslides_use_featured', 9999, 4 );
    }
}

Leave a Comment