If you don’t want to modify the template files directly, you could always make use of the post_thumbnail_html
filter:
function wpse70960_filter_post_thumbnail_html( $html ) {
if ( ( is_home() || is_single() ) {
return '';
} else {
return $html;
}
}
add_filter( 'post_thumbnail_html', 'wpse70960_filter_get_post_thumbnail_html' );
This code snippet goes either in your functions.php file or in a custom (mu-) plugin.
Edit
From your comment:
Im using a static page for the homepage and blog is using a new page I created in the WP CMS using a template file called Blog page. The homepage is rending the featured image for posts which is what I need. I want to avoid using the Featured image in the blog page and the singe page.
There are two approaches:
- Don’t use a custom page template to display the blog posts index. It’s not necessary. Assuming that template file is
template-blog.php
, copy that file, and rename it ashome.php
. Then go toDashboard -> Settings -> Reading
, and set “Page for posts” to the Page that is/was using the custom page template. That should solve the problem, and ensure that you don’t lose any formatting. -
Alternately, inside your filter callback, add the following:
global $post; $page_template = get_post_meta( $post->ID, '_wp_page_template', true ); if ( ( is_home() is_single() || 'template-blog.php' == $page_template ) { // etc. }
Edit 2
Full code, using alternative #2 above:
function wpse70960_filter_post_thumbnail_html( $html ) {
global $post;
$page_template = get_post_meta( $post->ID, '_wp_page_template', true );
if ( ( is_home() || is_single() || 'template-blog.php' == $page_template ) {
return '';
} else {
return $html;
}
}
add_filter( 'post_thumbnail_html', 'wpse70960_filter_get_post_thumbnail_html' );