• Resolved nummernegen

    (@nummernegen)


    Hello Tijmen or fellow readers,

    How could I get url of store’s featured image?
    I tried get_the_post_thumbnail_url function without success yet.
    The post/store ID I easily can get by <%= id %>.

    The aim is to get the image in a lightbox (class=”swipebox) after clicking the store’s image.

    In the function.php I added:
    $info_window_template .= '<div><a class="swipebox" href="' . 'IMAGE URL??' . '"> <%= thumb %> </a></div>' . "\r\n";

    The lightbox works when tested with a hard coded demo url. Now I would need the url as a variable.

    thank you

    • This topic was modified 2 years, 8 months ago by nummernegen.
    • This topic was modified 2 years, 8 months ago by nummernegen.
    • This topic was modified 2 years, 8 months ago by nummernegen.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi there!

    We have some documentation on how to display the featured image in the store pages.

    If you want to show this image in the store listing or the info window template, you can try something like:

    add_filter( 'wpsl_store_meta', 'custom_store_meta', 10, 2 );
    
    function custom_store_meta( $store_meta, $store_id ) {
        
        $url = the_post_thumbnail_url( $store_id, 'medium' );
        $store_meta['post_thumbnail_url'] = $url;
    
        return $store_meta;
    }

    And then you can use the <%= post_thumbnail_url %> variable inside the wpsl_listing_template or wpsl_info_window_template filters.

    Bear in mind that the the_post_thumbnail_url function returns the image url already embedded in an tag with the size you chose in the function call.

    I hope that helps.
    Regards,

    Thread Starter nummernegen

    (@nummernegen)

    hi @farroyob

    that works well! Exactly what I had in mind.
    The only code I had to change was: get_the_post_thumbnail_url instead of the_post_thumbnail_url

    the working version:

    add_filter( 'wpsl_store_meta', 'custom_store_meta', 10, 2 );
    
    function custom_store_meta( $store_meta, $store_id ) {
        
        $url = get_the_post_thumbnail_url( $store_id, 'medium' );
        $store_meta['post_thumbnail_url'] = $url;
    
        return $store_meta;
    }

    best

    That is super! I’m glad you made this work.

    Regards,

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get featured image url’ is closed to new replies.