Display default featured image with query loop block / latest posts block?
-
Hello, I’m using the query loop block and the latest posts block. They can show the featured image. However they do not show the default featured image, if the theme has set one in functions.php.
In other words, in functions.php I am using code like this:
See in Github: https://gist.github.com/paaljoachim/df42fde2ed57b5589813
/** Define a default post thumbnail */ add_filter('genesis_get_image', 'default_image_fallback', 10, 2); function default_image_fallback($output, $args) { global $post; if( $output || $args['size'] == 'full' ) return $output; $thumbnail = CHILD_URL.'/images/mydefaultimage.svg'; switch($args['format']) { case 'html' : return '<img src="'.$thumbnail.'" class="defaultimage alignnone attachment-'. $args['size'] .'" alt="'. get_the_title($post->ID) .'" />'; break; case 'url' : return $thumbnail; break; default : return $output; break; } }
This successfully shows mydefaultimage.svg in ‘regular’ archives such as blog category pages when no other featured image is set for a post.
However, when I insert the query loop block or latest posts block into the Block Editor, the default featured image does not show up at all.
To confirm, posts with a featured image defined from the media library do show up with the query block or latest posts block.
I have tried:
- Using other code to define the default post thumbnail such as: https://carlofontanos.com/set-a-default-featured-image-for-your-posts-in-wordpress/ or https://justintadlock.com/archives/2012/07/05/how-to-define-a-default-post-thumbnail
- Re-saving permalinks after trying the code options noted above
- Clearing cache after trying the code options noted above
To no avail.
I have also tried googling this issue but to be honest, I can’t even think of the right words to Google to solve this. I have not found anything matching what I need nonetheless.
My question:
Does anyone know if something is wrong with the code above that causes the default featured image not to show in the query loop block or latest post block? Does anyone have alternative code I could use?
What I do not want to do:
- Use a plugin (if possible)
- Remove the featured image
- Use the first image in the post as the featured image
- The topic ‘Display default featured image with query loop block / latest posts block?’ is closed to new replies.