Issue
There are multiple posts in three categories.
The categories are
- News (Feedzy)
- Images
- Videos
If any post that Post’s Feature image was shown in top of the article. But other two categories is ok but in Videos category we don’t want to display feature images.
Note: we are setting feature images for videos category because we are using that image for archive posts.
Solution
WordPress provides has_category() function to check if post has specific category.
There are 2 option to add your code
- Code on single.php (Need to create a child theme)
- PHP Raw widget (https://www.dynamic.ooo/widget/php-raw/)
The PHP will need to be like something in given below
if( !has_category('videos') ){
the_post_thumbnail('post-thumbnail', ['class' => 'op-post-featured-image', 'title' => 'Feature image']);
}
//if post has 'videos' category. And if it is false then the feature image will be displayed.
My easily option is code PHP directly in Theme Builder
- Go go Template > Theme Builder > Single Post
- Replace Feature image widget with PHP Raw widget
- Example site: https://rdergo.kinsta.cloud/blog