How to get image url from post loop?

Question

WordPress 5.5.1
localhost

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(); ?>

    <?php
    $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; ?>
0
Marke 4 months 0 Answers 24 views 0

Leave an answer