I’m not sure why you cannot just create a child theme and then simply copy the single template to your child theme and remove the code, but anyways, this is still a very interesting approach.
Regardless what have been said in comments using CSS to hide the thumbnail (which I do not support as it will still show in the browser source), there are better programmatic ideas to get rid of post thumbnails.
The best idea here would be to get the has_post_thumbnail()
conditional return false only on single pages. To do this is super easy, we just need to follow the source code. Here is how it works
-
has_post_thumbnail()
usesget_post_thumbnail_id()
which uses -
get_post_meta()
which uses -
get_metadata()
which is filterable through -
the
get_{$meta_type}_metadata
filter which holds our answer
The {$meta_type}
part will be post
as we will be using this filter to target posts, so our filter will be get_post_metadata
.
So, in this filter, we need to set the first parameter $value
to false
. From the source
Returning a non-null value will effectively short-circuit the function.
We would also only want to trigger this filter only for single posts and for post thumbnails, to will will check if we are on a single page and that our current $meta_key
is _thumbnail_id
which is the custom field key where the post thumbnail ID is stored.
With this all in mind, you can try the following
add_filter( 'get_post_metadata', function ( $value, $object_id, $meta_key )
{
if ( is_single() // Make sure we are on a single post page
&& $meta_key === '_thumbnail_id' // Only run the filter for post thumbnails
)
return false; // Breaks the function which in turn return false for has_post_thumbnail()
return $value;
}, 10, 3 );