Setup A Default Featured Image

One simple method is to filter post_thumbnail_html, to add in a default image link: <?php function wpse55748_filter_post_thumbnail_html( $html ) { // If there is no post thumbnail, // Return a default image if ( ” == $html ) { return ‘<img src=”‘ . get_template_directory_uri() . ‘/images/default-thumbnail.png” width=”150px” height=”100px” class=”image-size-name” />’; } // Else, return the … Read more

Possible to swap in a placeholder image globally for the_post_thumbnail_url if one doesn’t exist?

If you know the URL of the placeholder image, you sure can do it. get_the_post_thumbnail_url() function calls the wp_get_attachment_image_url() function which in turns calls the wp_get_attachment_image_src() function to get the source of the post thumbnail. wp_get_attachment_url() returns the result from wp_get_attachment_image_src filter. So we can use that filter to modify the result if there is … Read more

the_post_thumbnail fallback using hooks

you can use the post_thumbnail_html filter hook which passes 5 variables to your hooked function : $html – the Output html of the post thumbnail $post_id – the post ID. $post_thumbnail_id – the attachment id of the image $size – the size requested or default $attr – Query string or array of attributes. So something … Read more