Hide featured image on posts

Community Forums Forums Design Tips and Tricks Hide featured image on posts

This topic is: not resolved

This topic contains 1 reply, has 2 voices, and was last updated by  TravisPri 7 months, 1 week ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #60662

    wyattwerner
    Participant
    Post count: 13

    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)

    #60715

    TravisPri
    Participant
    Post count: 29

    I 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!

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.