Site icon WP Smith

How to Prevent Featured Images in Custom Post Types

So recently, someone asked if they could enabled Genesis Featured Images in Genesis > Theme Settings yet "disable" them for custom post types. While there is no option for this, it can be done! This is a rather simple task that can be complicated if post types are mixed and other circumstances. However, let's assume a simple setup.

In functions.php or your core functionality plugin where you created the custom post types, enter this code:
[php]
add_action( 'genesis_before_post_content', 'wps_do_post_image_check' );
/*
* Remove genesis_do_post_image() action if on post type archive of
* a custom post type
*
* @global stdClass $post Post object
* @uses genesis_get_option() Gets the genesis option for content archive thumbnails
*/
function wps_do_post_image_check() {
global $post;
if ( ! is_singular() && genesis_get_option( 'content_archive_thumbnail' ) && is_post_type_archive() && ! in_array( $post->post_type, array( 'page', 'post', 'attachment' ) ) )
remove_action( 'genesis_post_content', 'genesis_do_post_image' );
}
[/php]

NOTE: Though posts, pages, and attachments by default do not have archive pages, I cannot assume that in this code snippet.