How to Remove Thumbnail Support from a Specific Post Type in WordPress

Home » Snippets » How to Remove Thumbnail Support from a Specific Post Type in WordPress
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

There are times when you may want to remove the thumbnail or featured image support from a specific type of post in WordPress. Maybe the post type doesn’t require an accompanying image, or perhaps you want a cleaner look for specific content. Whatever the reason, WordPress gives you the flexibility to customize post types to your liking. In this tutorial, we’ll guide you through the steps needed to remove thumbnail support from a specific post type in WordPress.

					function wpturbo_remove_thumbnail_support() {
    remove_post_type_support( 'your_post_type', 'thumbnail' );
}
add_action( 'init', 'wpturbo_remove_thumbnail_support' );
				

In this code snippet, we’ve defined a function wpturbo_remove_thumbnail_support(), which is built to remove the thumbnail support from a specific custom post type in WordPress.

We’re using the WordPress function remove_post_type_support() inside our custom function to achieve this.

The remove_post_type_support() function is a built-in WP function and requires two parameters. The first one is ‘post_type’ – the post type from which we want to remove the support; and the second one is the ‘feature’ – the feature that we want to remove.

remove_post_type_support( 'your_post_type', 'thumbnail' );

In our case, ‘your_post_type’ should be replaced with the post type that you target (for example ‘products’, ‘events’ etc.) and ‘thumbnail’ is the feature we want to remove. The ‘thumbnail’ feature allows a post to have a featured image. By removing this feature, we disable the possibility to add a featured image to the specified post type in the WordPress Admin Dashboard.

Now, it’s not enough to simply declare this function. We also need to make sure it’s called at the right time. We do this by ‘hooking’ it into WordPress’s init action.

add_action( 'init', 'wpturbo_remove_thumbnail_support' );

The add_action() function is what allows us to call our custom function. By hooking ‘wpturbo_remove_thumbnail_support’ function to the ‘init’ action, we instruct WordPress to call this function when it fires the ‘init’ action, which is one of the the earliest action hook in WordPress, fired just after the website has finished loading but before any headers are sent. This ensures that our function is executed at an appropriate time to effectively remove the thumbnail support from our targeted post type.

In conclusion, by combining the use of a custom function, the built-in remove_post_type_support() function, and the ‘init’ hook, we can efficiently remove thumbnail support from a specific post type in WordPress.

Register an account to save your snippets or go Pro to get more features.