Is it possible in the post template, in the CSS code to embed a link to a featured image? Like this:
.some_class {
background-image: url(_featured_image_from_current_post_);
}
Is it possible in the post template, in the CSS code to embed a link to a featured image? Like this:
.some_class {
background-image: url(_featured_image_from_current_post_);
}
I usually prefer to do the same effect with an Image element positioned absolute in a parent that is positioned relative (and possible overflow to hidden for parent). It’s same as background-image and you have even better control.
Alternatively you could print the css code to WP head with a filter and then use this class, something like this added to functions.php or through Code Snippets Plugin:
function prefix_add_featured_image_background_style() {
if (is_singular() && has_post_thumbnail()) {
$featured_image_url = get_the_post_thumbnail_url();
if ($featured_image_url) {
echo "<style>
.some_class {
background-image: url('{$featured_image_url}');
}
</style>";
}
}
}
add_action('wp_head', 'prefix_add_featured_image_background_style');