Archived topic
Category images in Elements Category header
3 replies · Started by Guido on June 26, 2019
Hi there,
I added a small plugin 'Category & taxonomy image' to be able to add an image to a category.
I added an Element for the header, and selected 'Post Category Archive for all categories' as display rule.
On the page hero tab I set Background image to -featured image- with a fallback image.
But the category image I set with the plugin does not show up, only the fallback image.
This is code snippet I had to add for the plugin:
if (function_exists('get_wp_term_image'))
{ $meta_image = get_wp_term_image($term_id);
}
echo $meta_image; // category/term image url
Hi there,
Try this filter:
add_filter( 'generate_page_hero_background_image_url', function( $url ) {
$background_image = '';
if ( function_exists( 'get_wp_term_image' ) ) {
$background_image = get_wp_term_image( get_queried_object_id() );
}
if ( $background_image ) {
$url = $background_image;
}
return $url;
} );
This assumes that the plugin function returns the URL of the image.
This works! Thank you very much.
You're welcome :)