Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1386398
    bdestrempes
    Participant

    Hey guys,

    I’m trying to set the featured image URL as the background image for the entry-featured div instead of calling it as an image within the div. Here is what I have so far:

    <div class="entry-featured" <?php if (is_home()) echo 'style="background-image: url(' . the_post_thumbnail_url('thumbnail') . '"'; ?> >

    However, the end result is this:

    <div class="entry-featured" http:="" localhost="" wp-content="" uploads="" 2017="" 02="" the-three-people-you-meet-on-earth-150x150.jpgstyle="background-image: url(">

    I know I’m probably missing something really simple but my PHP skills are quite lacking. Any help would be appreciated.

    #1386683
    Lely
    Moderator

    Hi There,

    No need to use the echo function because the the_post_thumbnail_url function returns the URL already. Please use something like this instead:

    <?php if (is_home()){ ?>
          <div class="entry-featured" style="background-image: url(<?php the_post_thumbnail_url('thumbnail'); ?>">
    <?php }else {?>
          <div class="entry-featured">
    <?php }?>

    Hope this helps.

    #1386738
    bdestrempes
    Participant

    That did it, thanks a lot!

    #1386843
    Lely
    Moderator

    You’re welcome!

    Cheers!

  • <script> jQuery(function($){ $("#no-reply-1386398 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>