How to Remove the Featured Image in WordPress

How to Remove the Featured Image in WordPress

The latest versions of WordPress allow one single image to be directly associated with every post. This “Featured Image” is displayed in a variety of places. It’s almost invariably shown on archive pages, single post pages, and picked up by social media networks as the representative image of your post. Different themes use them in various ways. Some of them may choose to automatically display the featured image at the top of every single post page. This may or may not suit your plans for how you want your site to look.

There is a specific WordPress function called “the_post_thumbnail” which themes use to pick up the associated image with a given post and display it. What if you found a theme that suits you perfectly, but you don’t want to display the featured image in various places? In this tutorial, I’ll show you two ways to remove the featured image in WordPress – one via CSS, and one through a filter.

Using the Filter – the Proper Way

Let’s take my test website as an example. In this, I’ve created a sample post with a random featured image using the options on the right-hand side of every WordPress post editor as shown here:

featured image set

In the default WordPress themes that come with every stock installation of WordPress, the featured image is displayed on both the homepage above every post entry as well as single post pages:

shown on main page

Let’s say for instance that we want to get rid of the display of the featured image in single pages only, but we want to retain it on the main homepage and other archives. This doesn’t mean that we don’t want to display the featured image in our posts at all. It just means that we want to be able to show it on our terms – perhaps within the post content itself if we like.

To achieve this goal of disabling the automatic placement of featured images within a single post, open up your functions.php file and paste in the following at the end before the closing “?>” PHP tag:

function my_post_image_html( $html, $post_id, $post_image_id ) {
if(is_single()) {
return '';
} else

return $html;
}
add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );

If you don’t know how to add code snippets to WordPress, read my earlier tutorial on the same. This hooks into the “post_thumbnail_html” filter, checks whether or not it is a single page and if true, returns an empty string. You can modify this example to only hide featured images of a certain size by checking out the filter documentation.

However, if you don’t want to add PHP code to WordPress, you can opt for the quick and dirty method of hiding via CSS.

Hiding the Featured Image via CSS

This is a poor alternative to the first method because it doesn’t actually prevent the featured image from being downloaded onto the page – it only hides it. This is a waste of resources not just on your server or CDN, but also for the user who is receiving content they will never view. But if for whatever reason you prefer to tackle this issue via CSS, inserting the following CSS code will hide ALL featured images added via the ‘the_post_thumbnail’ function:

.wp-post-image {
    display: none !important;
}

Note that this is a blanket tool and doesn’t check for whether or not the page is single. Though you can use classes other than “wp-post-image” to hide featured images of specific sizes. Here is a list of other possible classes you can use

img.wp-post-image
img.attachment-thumbnail
img.attachment-medium
img.attachment-large
img.attachment-full

So for example if you want to hide only the featured image thumbnails, you would use the following:

.img.attachment-thumbnail {
    display: none !important;
}

Using the tools shown above, you can precisely pinpoint the areas where you want the featured image to show and hide or disable undesirable placements.

7 Comments on “How to Remove the Featured Image in WordPress”!

  1. do you know how to disable featured image for a specific type of post like Video posts for example?

    I am trying to disable featured image from showing up for video posts only. I am sure there is some way to do that in functions.php. thanks.

    • function my_post_image_html( $html, $post_id, $post_image_id ) {
      if(is_singular( ‘video’ ) ){
      return ”;
      } else

      return $html;
      }
      add_filter( ‘post_thumbnail_html’, ‘my_post_image_html’, 10, 3 );

  2. Hi.

    I’ve tried the above code and it doesn’t appear to be working.

    I’ve pasted this

    function my_post_image_html( $html, $post_id, $post_image_id ) {
    if(is_single()) {
    return ”;
    } else

    return $html;
    }
    add_filter( ‘post_thumbnail_html’, ‘my_post_image_html’, 10, 3 );

    Here

    $action = $_POST[‘action’];
    if ($action == “wdwt_lightbox”) {
    require_once(‘inc/front/WDWT_lightbox.php’);
    $lightbox = new WDWT_Lightbox();
    $lightbox->view();
    }
    die();
    }

    ?>

    So it looks like

    $action = $_POST[‘action’];
    if ($action == “wdwt_lightbox”) {
    require_once(‘inc/front/WDWT_lightbox.php’);
    $lightbox = new WDWT_Lightbox();
    $lightbox->view();
    }
    die();
    }

    function my_post_image_html( $html, $post_id, $post_image_id ) {
    if(is_single()) {
    return ”;
    } else

    return $html;
    }
    add_filter( ‘post_thumbnail_html’, ‘my_post_image_html’, 10, 3 );

    ?>

    And the images still appear.

    Any other suggestions?

    Regards. James

  3. Your php code works nice, removes the featured post, but the problem is that it also removes featured images from “Related Posts” plugin, which also uses featured images. How do you get around it?

  4. The function worked great! Thanks.
    I googled everything, I looked at some now obsolete plugins and watched a half dozen videos with no success. But I much rather have a function for my functions file. Thanks again

Leave a Reply

This Website is Hosted by

Powered by RamNode

Disclosure: We receive a compensation from some of the companies whose products or services are presented on our website.