Site logo

Archived topic

how do I get the featured image as background image with generateblocks?

9 replies · Started by Joost on November 7, 2020

Viewing posts 1–10 of 10

Hi, i'd like to create a header for a custom post type with a featured image as a background image with a post tile, category text over it. How do I pull this dynamic data into the generatepress block?

Hi there,

you can add featured image backgrounds in GenerateBlocks 1.2 - its currently available for Alpha testing:

https://generateblocks.com/generateblocks-1-2-0/

Post title and Meta is something to come later within GeneratePress Premium

Hi David,

That is awesome..it's working like a charm!

thank you

Glad to hear that!

Hello, I'm struggling to find this feature...apologies if I'm missing the obvious!

Thanks

Hi there,

the feature was removed from the final release, as we realised it was not the best most future compatible method for doing this... we're working on dynamic content for GP Premiums Element Block which will support this first, after that we will look at integrating that tech into GB.

Thanks for getting back to me. A bit of a long shot but is it possible to enable Featured Images on Elements? If so I may be able to use Toolset to pull through the Featured Image dynamically but Featured Image doesn't show as an option when using a Toolset container in Elements presumably because Elements don't have a Featured Image?

Many thanks.

Currently the Featured image is only available within the Header Element.
It will be added to the Block Element in the next update however.

You can of course get the Featured Image URL using the get_the_post_thumbnail_url function:

https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/

Then simply hook into the WP Head to output the styles for a custom-class eg.

<?php
$featured_img_url = get_the_post_thumbnail_url($post->ID, 'full'); 
if ($featured_img_url) {
	$style = printf(
		'<style>.custom-class {background: url(%1$s);}</style>',
		$featured_img_url
	);
	return $style;
}
?>

Thanks David. I'll take a look at this option until the next update.

You're welcome

This archived topic is closed to new replies.