How to get image url from post loop?


WordPress 5.5.1

I want to get an image on post url. I’m not really used to the new block post editing in wordpress.

They got rid of the featured image attachment. What I done was add the image as a block to the post and was wondering how to get URL of that image.

The below code doesn’t seem to return anything it is just blank.

 <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    $featured_img_url = wp_get_attachment_image_src(get_the_ID(), 'medium');
    echo $featured_img_url

    <li class="slideshow__item" style="content:'<?php the_title(); ?>'; background-image: url('<?php $featured_img_url ?>') ;">

    <?php endwhile; ?>

  <?php else : ?>

  <?php endif; ?>
Marke 2 years 2020-09-26T20:10:19-05:00 0 Answers 24 views 0

Leave an answer