Archived topic
If there is no Featured Image
1 reply · Started by onalti on October 1, 2020
Viewing posts 1–2 of 2
I am using this filter for custom post type. If there is no featured photo, I want to show something else instead. How can I do this?
add_filter( 'generate_featured_image_output','lh_custom_size' );
function lh_custom_size($output) {
if ( is_archive( 'results_category' ) ) {
return sprintf( // WPCS: XSS ok.
'<div class="post-image">
<a href="%1$s">
%2$s
<span class="results_media_stamp shellbell"></span></a>
</div>',
esc_url( get_permalink() ),
get_the_post_thumbnail(
get_the_ID(),
apply_filters( 'generate_page_header_default_size', '' ),
array('itemprop' => 'image', ))
);
}
return $output;
}
Hi there,
Try this:
add_filter( 'generate_featured_image_output', function( $output ) {
if ( is_archive( 'results_category' ) ) {
if ( has_post_thumbnail() ) {
return sprintf( // WPCS: XSS ok.
'<div class="post-image">
<a href="%1$s">
%2$s
<span class="results_media_stamp shellbell"></span>
</a>
</div>',
esc_url( get_permalink() ),
get_the_post_thumbnail(
get_the_ID(),
apply_filters( 'generate_page_header_default_size', '' ),
array('itemprop' => 'image' )
)
);
} else {
return 'something else';
}
}
return $output;
} );
This archived topic is closed to new replies.