[Resolved] Category images in Elements Category header

Home Forums Support Category images in Elements Category header

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #942535
    Guido

    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

    #943039
    Tom
    Lead Developer
    Lead Developer

    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.

    #943731
    Guido

    This works! Thank you very much.

    #943912
    Tom
    Lead Developer
    Lead Developer
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.