WordPress.org

Support

Support » How-To and Troubleshooting » hide post thumbnail with custom field?

hide post thumbnail with custom field?

  • Hi!

    I want to hide a thumbnail in a post – but only in the single view (the post thumbnail should show up everywhere else).

    I tried it with a custom field called hidethumb, so when it is activated it should just show nothing but doesn’t work:

    <?php

    $hidethumb = get_post_meta($post->ID, “hidethumb”, true);

    if ( function_exists(‘has_post_thumbnail’) && has_post_thumbnail() ) {
    the_post_thumbnail(array(150,150), array(“class” => “alignleft post_thumbnail”));

    else if ($hidethumb) {
    echo “”;}
    ?>

    any suggestion?

    Thank you!!

    AD

Viewing 4 replies - 1 through 4 (of 4 total)
  • you are testing for your custom field after the post thumbnail is shown, and only if there is no post thumb.

    try:

    <?php
    
    $hidethumb = get_post_meta($post->ID, "hidethumb", true); 
    
    if ( !$hidethumb && function_exists('has_post_thumbnail') && has_post_thumbnail() ) {
    the_post_thumbnail(array(150,150), array("class" => "alignleft post_thumbnail"));
    
    ?>

    Hi alchymyth,

    thank you for the reply! Works!

    AD

    Hoping one of you can help, I’m having a similar issue and its driving me crazy. I would like to hide the post thumbnails on certain single pages/categories. Here is a link to my site http://www.wellnessbysandra.com/new

    I would like to remove the thumbs on the tip pages…

    any help will be greatly appreciated!

    Same as anjoid, I also want to hide post thumbnails on single posts, but only on posts using a specific category (in my case ‘graphics’).

    Thank you for any help! 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘hide post thumbnail with custom field?’ is closed to new replies.
Skip to toolbar