Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #1181839

    I know I can just hide the featured image in CSS, but I’d prefer not loading the image in the first place than loading and hiding it.
    Sure I can just comment loop-portfolio-single.php to remove the thumb, and this is what you guys advised to do until a few months (years?) when you introduced ‘_avia_hide_featured_image’ which allow us to “Hide on single entry” using entry’s Layout options.

    Now, the problem is I have over 480 portfolio items (2400 including localisations) and of course I don’t want to change everyone of them.
    Is there a way to set a default option?
    Or maybe you can provide the correct MySQL request to run on my database?

    I’m sure it would help others than me.
    Thanks

    #1182317

    Hey Julien,
    Try adding this code to the end of your functions.php file in Appearance > Editor:

    
    //disable featured image
    function disable_featured_image( $html, $post_id, $post_image_id ) {
        if(is_single()) {
        return '';
        } else
        
        return $html;
        }
        add_filter( 'post_thumbnail_html', 'disable_featured_image', 10, 3 );

    Best regards,
    Mike

    #1183004

    Well, thank you Mike, that’s a start.
    Since I want to hide featured images on portfolios only (not blog posts nor other custom posts), I could change it like this:

    function disable_portfolio_featured_image( $html, $post_id, $post_image_id ) {
        if(is_singular('portfolio')) {
        	return '';
        } else    
        return $html;
    }
    add_filter( 'post_thumbnail_html', 'disable_portfolio_featured_image', 10, 3 );

    But there’s still a glitch.
    Using this code not only hides featured image on top of page, it also hides featured images on a “related posts” at page bottom (which is a 4 items “portfolio grid” Enfold element).
    I don’t see how I could limit the effect to .entry-content-header .page-thumb .wp-post-image (except using some CSS, I don’t want to hide it, I want to prevent it loading).

    Using a function would be great, but if it’s not possible (without overriding loop-portfolio-single.php), I guess the MySQL request could still be something worth doing. I’m just not very confortable with.

    #1183053

    Hi,
    I see, sorry I’m not that comfortable with MySQL either.
    I will ask the rest of the team to take a look, Thank you for your patience.

    Best regards,
    Mike

    #1183462

    Hi!

    Thank you for the update.

    You can add a condition inside the filter based on the value of the image size used in the get_the_post_thumbnail function. For example, in the related posts section the name of the thumbnail is square, so the condition will look something like the following.

    if($size != 'square') {
       return '';
    }

    // https://developer.wordpress.org/reference/hooks/post_thumbnail_html/

    Cheers!
    Ismael

    #1183581

    Thank you Ismael.
    I really tried to understand your lead but I fear I wasn’t able to do it.

    Should I try to update the above filter provided by Mike to include this condition on image size?
    Specifically, in my case, the portfolio featured image on top uses ‘entry_with_sidebar’ image size, so I could try a

    if($size = 'entry_with_sidebar') {
       return '';
    }

    but I don’t understand how to use this in Mike’s filter.
    (sorry, I’m still a beginner in WP hooks, but I’m willing to learn)

    #1183718

    Hi!

    Thank you for the update.

    Should I try to update the above filter provided by Mike to include this condition on image size?

    Yes, that is correct. You can add the condition inside the filter that @mike suggested above.

    function avf_disable_portfolio_featured_image( $html, $post_id, $post_image_id, $image_size ) {
        if(is_singular('portfolio') && $image_size == 'entry_with_sidebar') {
        	$html = '';
        }
        return $html;
    }
    add_filter( 'post_thumbnail_html', 'avfdisable_portfolio_featured_image', 10, 4 );

    Best regards,
    Ismael

    #1183816

    Well, that’s more or less what I had tried, and it doesn’t really work as expected.
    It does remove the featured image on top of page, but also removes the ‘portfolio’ images on the ‘portfolio grid’ element at page bottom.
    It actually does the exact same thing than Mike’s code. :s
    Any idea of what we’re missing?
    Do you want to have a look on the page?

    #1183848

    Hi!

    Yes, please post the login details in the private field so that we can test the filter. Make sure that the Appearance > Editor panel is accessible.

    Cheers!
    Ismael

    #1183870

    Sure.
    The function is at the bottom of functions.php (commented).

    Please note I have hidden the featured image at page top using:

    .single-portfolio .entry-content-header .page-thumb {
    	display: none;
    }

    When activating the filter, the image in entry-header is removed, but also those in the “Related” portfolio-grid at page bottom.

    #1184417

    Hi,

    Thank you for the update.

    We missed an underscore in the function or callback name, so instead of avf_disable_portfolio_featured_image, it was named avfdisable_portfolio_featured_image. We corrected the function name. It is working properly now.

    Best regards,
    Ismael

    #1184459

    arf, it’s so obvious now.
    If I had been more confident in my own skills, I would have seen it. ^^
    Thank you for your help, I learned a lot here.

    #1184697

    Hi,

    Great, I’m glad that Ismael could help you out. Please let us know if you should need any further help on the topic or if we can close it.

    Best regards,
    Rikard

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

You must be logged in to reply to this topic.