Archived topic
Default featured image
26 replies · Started by guevara on December 9, 2021
Hello,
I would like to have a default image for all posts without a featured image. Please help.
tried it but it doesnt update hence my question.
You can try the PHP Snippet that Tom provided here:
https://generatepress.com/forums/topic/default-fallback-featured-image/page/2/#post-510939
not working, Thanks
Hi there,
What was the exact code you used?
And can you link us to your site?
add_filter( 'post_thumbnail_html', 'tu_post_thumbnail_fallback', 20, 5 );
function tu_post_thumbnail_fallback( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
if ( empty( $post_thumbnail_id ) ) {
$html = '';
}
return $html;
}
please find below
Since you are using block element - content template for the blog page, the easiest way would be edit the content template, using a container block with background image instead of using the dynamic image block.
So the structure can be something like this:
https://www.screencast.com/t/BYFen5qfLl
Choose a background image for the container block, this image will be the fall back image for posts that don't have featured image, activate the use fall back image option:
https://www.screencast.com/t/wBabfzj9U3
Let me know if this helps :)
Sorry I am bit confused - can you break the process down a bit so that I can understand it more. Thanks
Which part do you not understand?
I am not using an element for the blog page as such just a header block page hero. Where exactly am I expected to edit?
You are using a block element - content template for the blog:
https://www.screencast.com/t/gTow9rS1E
Can you go to appearance > elements, check if there's a block element - content template?
If you are not sure, can you enter the admin access in private info field so I can take screenshot for you?
Below
This is the element I was talking about:
https://www.screencast.com/t/lJytcnBVe
1. Remove the dynamic image block:
https://www.screencast.com/t/9VSWCo6KwmAa
2. Add a container block, so the structure becomes:
Container
- Container (add background image to it)
- Container
- Headline
- Headline
- Dynamic content
- Buttons
- Button