Hiding featured image on specific page


Is that possible?

Reason I ask is because on the home page it makes very little sense to receive people with a grand image, instead it serves more purpose to let them make a quick choice for what they require.

I know, with Google's recent changes it's a bad idea in some ways, but that can be compensated by using the specified image (with meta intact) elsewhere on the page.

I'm fairly certain that for single view the following should work

// Only apply if for single view.
if ( is_single() ) {
 beans_remove_action( 'beans_post_image' );
}

Which, however, is across the board. Not specific to a page.

// Only apply ot the front page and blog index.
if ( !is_front_page() ) {
    beans_remove_action( 'beans_post_image' );    
}

I think I'm missing something though?

Also, what if it's not the front page, but another one :/


I think I found it, or at least part of it. Thanks to some excellent discussions elsewhere on this forum (seriously loving the detail of feedback back & forth here).

// Only apply ot the front page and blog index.
if ( !is_front_page() && !is_home() ) {
    beans_remove_action( 'beans_post_image' );    
}

This however, intended for posts, removes the featured image from pages also. Unfortunately, the above is a case of copy & paste, I'm not code savvy enough to figure this one out I'm afraid :/


If I understand well, you want to remove the featured image on pages right? If it is the case, you should do it as such.

add_action( 'wp', 'example_setup_document' );

function example_setup_document() {

  if ( is_page() ) {
    beans_remove_action( 'beans_post_image' );
  }

}

Note that I have added example_setup_document so that other users can also use the snippet in their child theme functions.php.

Thanks,


Correct, but not for all pages. What I'm trying to do is find a way to specify which page to hide the featured image from.


you can hide them with php codes if you specify the page id but i'd recomend you to do it with css fir eg:-

At first add page id as class and do this

.page-id .tm-article-image {display:none}

@jcm you can set the page ID, title or slug in the is_page() function. So for example you can do is_page( 'i-m-a-page-slug' ).

@anupam it isn't good practice to use display: none. Moreover it is much more elegant to only load the image if needed and better performance wise too.


Yes thierry,

That's a good point but if anyone finds difficult to do this with php then this is a shortcut.


// Remove featured image on specified page.
add_action( 'wp', 'example_setup_document' );

function example_setup_document() {

    if ( is_page( 'i-m-a-page-slug' ) ) {
        beans_remove_action( 'beans_post_image' );
    }

}

Works!


Here is the code to remove the featured image from a post. (Just wanted to add into this thread.)

add_action( 'wp', 'beans_child_setup_document' );
function beans_child_setup_document() {
    // Only apply for single view.
    if ( is_single() ) {
        beans_remove_action( 'beans_post_image' );
    }
}

Originally from this thread: https://community.getbeans.io/discussion/how-to-remove-featured-images-from-posts/

Removing the featured image from a page:

add_action( 'wp', 'beans_child_setup_document' );
function beans_child_setup_document() {
    // Only apply for single view.
    if ( is_page() ) {
        beans_remove_action( 'beans_post_image' );
    }
}

To remove featured image from a single post AND a page.

// Removes featured image on single post AND a page.
add_action( 'wp', 'beans_child_setup_document' );
function beans_child_setup_document() {
   if ( is_single() or is_page() ) {         
        beans_remove_action( 'beans_post_image' );
    }
}

Write a reply

Login or register to write a reply, it's free!