How to hide featured image in WordPress Single Post

I want to hide the featured image in the post page, but not on the home page.
I had a look at the other posts about this same problem, but they didn’t work for me, so I will appreciate your help.

Here is my single.php

<div id="primary" class="full-width-page">
    <main id="main" class="site-main" role="main">

    <?php while ( have_posts() ) : the_post(); ?>

        <?php get_template_part( 'content', 'single' ); ?>

        <?php tesseract_post_nav(); ?>

        <?php
            // If comments are open or we have at least one comment, load up the comment template
            if ( comments_open() || get_comments_number() ) :
                comments_template();
            endif;
        ?>

    <?php endwhile; // end of the loop. ?>

    </main><!-- #main -->
</div><!-- #primary -->

Related posts

5 comments

  1. Add this to your functions.php (prefer child-theme), and that is it. It works on any theme, and you don’t need to touch the ugly HTML templates.

    function wordpress_hide_feature_image( $html, $post_id, $post_image_id ) {
      return is_single() ? '' : $html;
    }
    // add the filter
    add_filter( 'post_thumbnail_html', 'wordpress_hide_feature_image', 10, 3);
    

    References:
    https://helloacm.com/how-to-hide-feature-image-of-posts-in-wordpress/

  2. Please, write what theme you are using.
    According to what you wrote you have to edit content-single.php.
    Search for the line like this:

    get_the_post_thumbnail( $post->ID, ... );
    

    or

    the_post_thumbnail();
    

    And remove or comment it.

  3. The code is in the template part. You will find the feature image function in the file named ‘content-single’.

    There are two ways to disable:

    1. Find the code.

    Remove or comment the function in your content-single template file:

    <div class="thumbnail">
      <?php
        // Comment out this function:
        echo get_the_post_thumbnail( $post_id, $size, $attr );
        // or:
        the_post_thumbnail();
        // Or you can remove this <div> entirely
      ?> 
    </div>
    

    2. CSS method.

    Find the appropriate class of the image div and add a display none condition in your style sheet.

    .thumbnail{display:none}
    

    If you can share the site url I can answer more clearly.

  4. How to remove featured image background from Tesseract Theme single posts:

    1.- First of all make a copy from the original content-single.php file.

    2.- Edit content-single.php with a plain text editor.

    3.- If the original file is like this:

    <?php
    /**
    * @package Tesseract
    */
    ?>
    
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
      <?php if ( has_post_thumbnail() && 'post' == get_post_type() ) {
        $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'tesseract-large' ); ?>
        <div class="entry-background" style="background-image: url(<?php echo esc_url( $thumbnail[0] ); ?>)">
            <header class="entry-header">
                <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
            </header><!-- .entry-header -->
        </div><!-- .entry-background -->
    
      <?php } else { ?>
        <header class="entry-header">
            <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
        </header><!-- .entry-header -->
      <?php } ?>
    
      <div class="entry-content">
        <div class="entry-meta">
            <?php tesseract_posted_on(); ?>
        </div><!-- .entry-meta -->
        <?php the_content(); ?>
        <?php
            wp_link_pages( array(
                'before' => '<div class="page-links">' . __( 'Pages:', 'tesseract' ),
                'after'  => '</div>',
            ) );
        ?>
      </div><!-- .entry-content -->
    
    </article><!-- #post-## -->
    

    ( Source: github.com/Conutant/TESSERACT/blob/Master_Branch/content-single.php )

    4.- To remove the featured image background, change it to this:

    <?php
    /**
    * @package Tesseract
    */
    ?>
    
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
      <header class="entry-header">
            <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
      </header><!-- .entry-header -->
    
      <div class="entry-content">
        <div class="entry-meta">
            <?php tesseract_posted_on(); ?>
        </div><!-- .entry-meta -->
        <?php the_content(); ?>
        <?php
            wp_link_pages( array(
                'before' => '<div class="page-links">' . __( 'Pages:', 'tesseract' ),
                'after'  => '</div>',
            ) );
        ?>
      </div><!-- .entry-content -->
    
    </article><!-- #post-## -->
    

    5.- Remember that all changes will be overwritten when you update the theme to a new version. A good option to avoid this is to create a Child Theme, the recommended way of modifying an existing theme. More information can be found at: https://codex.wordpress.org/Child_Themes

    6.- Test it and let me know if you have any problem.

    Regards.

  5. In your code there is one line

    <?php get_template_part( 'content', 'single' ); ?>
    

    which means it calls content.php file of your current theme. go to that file and comment following code

    <?php if ( has_post_thumbnail() && ! post_password_required() && ! is_attachment() ) : ?>       <div class="entry-thumbnail">           <?php the_post_thumbnail(); ?>      </div>      <?php endif; ?>
    

    But note that it removes thumbnail everywhere when content.php file calls, so better idea is create custom single.php file. For that you need to copy in single.php file and rename with your post name.
    for example if you use post for add your content then rename with single-post.php or if you use custom post type like news then rename with single-news.php.

    After that open this file and remove this code

    <?php get_template_part( 'content', 'single' ); ?>
    

    from file and goto the content.php file and copy your require code which you want to display and paste in your new file.

Comments are closed.