How to remove featured image on post yet leave it on widget?

Hey. I got a plugin that removes the featured image from a post which works for my design, yet it also automatically removes the featured image with the widget I am enjoying using in the sidebar. I’m considering a workaround. I only want very select posts (those of the ‘Academy’) to have no featured image, so is there a way to remove the featured image on particular posts while leaving the image on the widget’s display?

Obviously, they’re hooking the same quality in the code and if one goes the other goes. I’m looking for a way around that.

This is s page w/the featured image disabled, which removes the images on the sidebar - https://intothemythica.com/rules-of-the-road/

and this is a page with the featured image and the sidebar images intact -

thanks

Hey @Peter_Fae,

Since your plugin removes the featured image, there is no way for it to be displayed in the recent posts.

The simplest solution for this is to hide the featured image of your Academy single post using CSS. Here’s the code for it.

.single-post .category-academy .entry-thumb {
    display: none;
}

You can also remove the featured image in a single post and for a certain category by overriding the featured image function which can be found in wp-content\themes\x\framework\functions\global\featured.php. For your case, you will need to change this part of the code switch ( is_singular() ) to switch ( is_singular() && is_category( 'academy' ) ) . The code inside the switch function are WordPress Conditionals. For more details, please see https://developer.wordpress.org/reference/functions/is_category/. Here’s the sample code to be placed in functions.php.

function x_featured_image( $cropped = '' ) {

  $stack     = x_get_stack();
  $fullwidth = ( in_array( 'x-full-width-active', get_body_class() ) ) ? true : false;

  if ( has_post_thumbnail() ) {

    if ( $cropped == 'cropped' ) {
      if ( $fullwidth ) {
        $thumb = get_the_post_thumbnail( NULL, 'entry-cropped-fullwidth', NULL );
      } else {
        $thumb = get_the_post_thumbnail( NULL, 'entry-cropped', NULL );
      }
    } else {
      if ( $fullwidth ) {
        $thumb = get_the_post_thumbnail( NULL, 'entry-fullwidth', NULL );
      } else {
        $thumb = get_the_post_thumbnail( NULL, 'entry', NULL );
      }
    }

    switch ( is_singular() && is_category( 'academy' ) ) {
      case true:
        printf( '<div class="entry-thumb">%s</div>', $thumb );
        break;
      case false:
        printf( '<a href="%1$s" class="entry-thumb" title="%2$s">%3$s</a>',
          esc_url( get_permalink() ),
          esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ),
          $thumb
        );
        break;
    }

  }

}

Please note that we are using custom code to achieve what you need. The code given serves only as a guide and might break in the future. With that said, issues that might arise from the use of the code and any enhancements would be outside the scope of our support. Please see our Terms of Use for more details.

Hope that helps.

That does help. Tell me then, how would I hide the featured images on a set of Pages instead that were all children of a particular page? In this case, they are children of ‘Academy’

(I decided to make those posts pages and have encountered the same issue w/the featured image)

Hey @Peter_Fae,

There is no function to check if a page is a sub-page. You will need to have a developer to change is_category( 'academy' ) with a custom condition.

Thank you for understanding.

Understood. The question then is, how do I remove the featured image on particular pages?

This code works for posts, yes?

.single-post .category-academy .entry-thumb {
display: none;
}

is there a css which can remove featured image on pages that I choose? I can adjust the CSS on the page level or the customizer level?

Hi there,

Actually, you can do that. The trick is to find the post ID of that specific post which you can do like this:

Now, for example, the post ID is 125. Then you will need to change the code to:

.postid-125.single-post .category-academy .entry-thumb {
	display: none;
}

If you want to have the code for more than one post you need to add for example something like this:

.postid-125.single-post .category-academy .entry-thumb,
.postid-126.single-post .category-academy .entry-thumb {
	display: none;
}

Hope it helps.

for posts AND Pages?

That’s for post. For pages, use a Blank page template. If you want a CSS solution, here’s the code.

.page .entry-thumb {
    display: none;
}

For specific pages, it should be .page-id-708 instead of .page. The instruction to get the page or post ID was given in the previous post by @christopher.amirian

Thanks.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.