Tagged: featured image, Portfolio
-
AuthorPosts
-
February 5, 2020 at 5:22 pm #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.
ThanksFebruary 7, 2020 at 2:44 pm #1182317Hey 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,
MikeFebruary 10, 2020 at 11:45 am #1183004Well, 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.
February 10, 2020 at 2:10 pm #1183053Hi,
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,
MikeFebruary 11, 2020 at 1:47 pm #1183462Hi!
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!
IsmaelFebruary 11, 2020 at 4:49 pm #1183581Thank 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 aif($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)February 12, 2020 at 2:20 am #1183718Hi!
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,
IsmaelFebruary 12, 2020 at 10:24 am #1183816Well, 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?February 12, 2020 at 1:25 pm #1183848Hi!
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!
IsmaelFebruary 12, 2020 at 1:50 pm #1183870Sure.
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.
February 14, 2020 at 7:44 am #1184417Hi,
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,
IsmaelFebruary 14, 2020 at 11:26 am #1184459arf, 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.February 15, 2020 at 8:32 am #1184697 -
AuthorPosts
- You must be logged in to reply to this topic.