Community Forums › Forums › Archived Forums › Design Tips and Tricks › Hide featured image on posts
Tagged: featured image, minimum
- This topic has 1 reply, 2 voices, and was last updated 10 years, 7 months ago by TravisPri.
-
AuthorPosts
-
September 4, 2013 at 10:55 am #60662wyattwernerMember
I'm using the Minimum theme, and I'd like to hide the featured image on particular posts. I assigned the post a body class (consumer-confusion) and tried to hide it with css using:
.consumer-confusion #featured-image { display: none !important; }
No dice, though. I can control other styles on the page like "p", but not #featured-image or even img.
I tried using the post id, too (post-2), but no avail. Again, I could control other styles, but not the featured image.
Any advice?
(the site is still in dev, so no URL; sorry)
September 4, 2013 at 3:39 pm #60715TravisPriMemberI think this would be a php issue.
The featured image section is coded in functions.php; look for "Add the featured image section." The code below should be in your existing theme and is what needs to be edited.
Before editing functions.php, make sure you have a copy of the file saved before making changes, and make sure you have ftp access to the site in case something goes wrong.
/** Add the featured image section */ add_action( 'genesis_after_header', 'minimum_featured_image' ); function minimum_featured_image() { if ( is_home() ) { echo '<div id="featured-image"><img src="'. get_stylesheet_directory_uri() . '/images/sample.jpg" /></div>'; } elseif ( is_singular( array( 'post', 'page' ) ) && has_post_thumbnail() ){ echo '<div id="featured-image">'; echo get_the_post_thumbnail($thumbnail->ID, 'header'); echo '</div>'; } }
I wanted to make it so there was no featured image on any posts, so my code looks like this:
/** Add the featured image section */ add_action( 'genesis_after_header', 'minimum_featured_image' ); function minimum_featured_image() { if ( is_home() ) { echo '<div id="featured-image"><img src="'. get_stylesheet_directory_uri() . '/images/sample.jpg" /></div>'; } elseif ( is_singular( array( 'page' ) ) && has_post_thumbnail() ){ echo '<div id="featured-image">'; echo get_the_post_thumbnail($thumbnail->ID, 'header'); echo '</div>'; } }
In order to hide the featured image on specific posts, you will need to target them in the php. I'm no php master and I don't want to mess up your site.. I haven't tried this on mine. Again, make sure you have a copy of your code and ftp access in case this breaks something and you have to put the original code back in.
I THINK the code would look like this [replace Post Titles in the last function with the titles of the posts you want to hide featured images on]:
/** Add the featured image section */ add_action( 'genesis_after_header', 'minimum_featured_image' ); function minimum_featured_image() { if ( is_home() ) { echo '<div id="featured-image"><img src="'. get_stylesheet_directory_uri() . '/images/sample.jpg" /></div>'; } elseif ( is_singular( array( 'post', 'page' ) ) && has_post_thumbnail() ){ echo '<div id="featured-image">'; echo get_the_post_thumbnail($thumbnail->ID, 'header'); echo '</div>'; } elseif ( is_single( array ( 'Post Title', 'Post Title 2', 'Post Title 3 ' ) ) ){ } }
For your reference: http://codex.wordpress.org/Function_Reference/is_single
Hope this helps!
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.