• Resolved sefanjo

    (@sefanjo)


    Hey guys!

    I am working on a site and I wanted to make sure that people could easily change the header/hero image. Therefor I wrote a tiny bit of PHP in my HTML.

    <div class="hero-sdc" style="background-image: url( <?php the_post_thumbnail('full'); ?> );">

    I can see and edit the picture so that is working. The only problem is that I can see some code/text on the picture. It is the part after I am closing the PHP tag that is shown to me.

    Does anyone know how to fix this?

    EDIT:
    I thought that the image was showing up, in fact it does not! Can anyone help me getting this fixed and right?

    • This topic was modified 7 years, 4 months ago by sefanjo.
    • This topic was modified 7 years, 4 months ago by sefanjo.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @sefanjo
    Hope you are doing well
    First problem that I notice is that you are using the wrong method to get the image url.
    Change
    the_post_thumbnail('full'); (this returns the whole img tag)
    to
    the_post_thumbnail_url('full'); (this returns just the image url)

    And I guess you are already aware that this will pick the featured image for the current post. (this won’t work in an archive view, for instance).
    You would need to add some conditional logic to check if there is an image available and use some kind of fallback.

    Take care!

    • This reply was modified 7 years, 4 months ago by Santiago.
    Thread Starter sefanjo

    (@sefanjo)

    Hey,

    Thank you! It is fixed now. 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Displaying too much’ is closed to new replies.