post

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:

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' );
}

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

About Travis Smith

As a WordPress Enthusiast, Travis writes about his journey in WordPress trying to help other WordPress travelers and enthusiasts with tutorials, explanations, & demonstrations of the things he learns.

Comments

  1. I just left you a comment on another post and wanted to say that the line 12 remove_action placed directly on my archive-cpt.php worked BEAUTIFULLY to fix my problem. Thanks so much.

Leave a Reply

%d bloggers like this: