Archived topic
Default Featured image
3 replies · Started by David on February 15, 2023
Hello,
Im designing a post loop and post template using generateblocks and generatepress. Is there a way of displaying a default featured image if one has not been applied to a post or category without using a plugin?
Thanks
David
Hi David,
There're two scenarios:
If you are using a container with a dynamic background image set to the featured image, you just need to upload an actual image, it will be the fallback image if there's no featured image.
If you are using a GB image block to pull the featured image, you can add one more image block with the fallback image below it, add a CSS class to the dynamic GB image block, eg. featured-image, so we can use CSS to target it.
Here's the block structure for your reference, the red one is the dynamic image, and the green one is the static fallback image:
https://www.screencast.com/t/ry7zgkE4
Here's the CSS:
.gb-query-loop-item .gb-block-image:has(.featured-image) + .gb-block-image {
display: none;
}
Thank you, that makes sense. I like solution 1 unfortunately I'm using generateblocks images, would have been good to have had that same feature in the image block as the background image in container.
Unfortunately, it's not available for image block.
You can try the second solution.