Home Forums Front-end Issues Getting image url from image ID Reply To: Getting image url from image ID

  • This works for echoing out the image field but the css is not working as the width and height are being added to the inline style:

    <div class="c-1 hero bg-image" style="background-image: url('<img width=" 1024"="" height="256" src="" alt="drama-holding" srcset=" 1024w, 300w, 768w" sizes="(max-width: 1024px) 100vw, 1024px">');">
      <div class="center-wrapper">
        <div class="center">
          <h1 class="cheddar">Drama</h1>

    Using your example above. Do I need to set this line to something else:

    <div class="c-1 hero bg-image style="background-image: url('<?php echo wp_get_attachment_image( $hero, $size ); ?>');">