post thumbnails - How to apply filter on get_the_post_thumbnail()

admin2025-01-08  3

my client want me to add a custom fields for thumbail, so the logic will be

if custom_thumnail is empty, render the origina. But i don't like idea of writing if statments everywhere + am using SEO plugins for open graph and images, so now i have to use filters to implement the custom thumbail.

i was thinking of wp filters but i didn't find one for get_the_post_thumbnail.

apply_filter('get_the_post_thumbnail',function(){
//my if statments
})

my client want me to add a custom fields for thumbail, so the logic will be

if custom_thumnail is empty, render the origina. But i don't like idea of writing if statments everywhere + am using SEO plugins for open graph and images, so now i have to use filters to implement the custom thumbail.

i was thinking of wp filters but i didn't find one for get_the_post_thumbnail.

apply_filter('get_the_post_thumbnail',function(){
//my if statments
})
Share Improve this question edited Dec 17, 2021 at 17:59 FS-GSW 3041 silver badge8 bronze badges asked Dec 17, 2021 at 8:24 Мохамед РуслановичМохамед Русланович 53 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can use the post_thumbnail_html filter. This filter is applied in the return of the get_the_post_thumbnail function.

apply_filters( 'post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736270565a1438.html

最新回复(0)