Getting Featured Image URL for use in Background Image

Home Forums Calendar Products Events Calendar PRO Getting Featured Image URL for use in Background Image

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1227801
    Christopher
    Participant

    I am trying to get the featured image url to use for a background image on my header banners. I tried using the code from this article but no luck.

    https://theeventscalendar.com/support/forums/topic/using-feature-image-as-background-image/

    <div class=”header-image-container” style=”background-image:url($url = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), ‘full’ ); echo $url[0];);”></div>

    nothing is showing up though.

    I’ve also tried using the_post_thumbnail_url(); but that doesn’t work either.

    #1228372
    George
    Participant

    Hi Christopher,

    Thanks for reaching out.

    We are not able to help with questions related to custom coding like this, so you’ll mostly have to take the reins here.

    A few tips, though:
    1. Try using the function get_the_ID() instead of trying to use $post->ID. You can learn more about this function here: https://developer.wordpress.org/reference/functions/get_the_id/

    2. Try using the function tribe_event_featured_image() to get an event’s featured image. You can learn more about this function by heading to this file within your The Events Calendar and reading the function’s code to see how it works:
    the-events-calendar/src/functions/template-tags/general.php

    3. Make sure you’re using PHP code within a template in a way that makes sense. This is a pretty broad/abstract thing to recommend, I’m aware; but research online for some real examples of people who’ve done similar things with other themes and plugins—it may be insightful.

    Please let me know if there are any other issues or questions I can try to help with.

    — George

    #1228418
    Christopher
    Participant

    It is kind of absurd that there is no function to grab the post thumbnail url. Why would you make it so this plugin can’t use the default WordPress functions that is something I’m sure a large number of people would want to do.

    #1228502
    Christopher
    Participant

    I figured it out. I wasn’t able to use those functions in my page.php but when I edited the single-event.php in the tribe events templates my code worked there for some reason.

    #1228679
    George
    Participant

    There are numerous functions to grab the post thumbnail URL, both from within WordPress itself, and some custom event-specific ones we have created and can be found in our plugin code.

    Best of luck with your site.

    George

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Getting Featured Image URL for use in Background Image’ is closed to new replies.