Tagged: default blog-thumbnail
Looking for a snippet to show a deafult image in blog views – but NOT Single view (there only images should be shwon, which are uplaoded with the post).
I tried it like this:
function enfold_fallback_thumb_url( $size = ‘enfold-blog-thumb’ ) {
// Deine Fallback-ID (anpassen!)
$fallback_id = 4283;
return wp_get_attachment_image_url( $fallback_id, $size );
}
// Enfold-kompatibler Filter: Nur Übersicht, kein Single
function enfold_fallback_thumbnail_html( $html, $post_id, $post_thumbnail_id ) {
global $post;
// Admin/Single/hat Bild: überspringen
if ( is_admin() || is_singular() || $post_thumbnail_id ) {
return $html;
}
// Nur Posts in Übersichten
if ( ! is_home() && ! is_archive() || $post->post_type !== ‘post’ ) {
return $html;
}
// Fallback-Bild rendern (Enfold-Size)
$fallback_html = ‘<img src=”‘ . enfold_fallback_thumb_url( ‘enfold-blog-thumb’ ) . ‘”
alt=”‘ . esc_attr( get_the_title( $post_id ) ) . ‘”
class=”attachment-enfold-blog-thumb wp-post-image fallback-thumb” />’;
return $fallback_html;
}
// Filter aktivieren
add_filter( ‘post_thumbnail_html’, ‘enfold_fallback_thumbnail_html’, 10, 3 );
But it doesn’t work. Any advices? Thakns
Tim
