1
votes

Our Wordpress site suddenly stopped showing all 'featured' images. They're just blank. When we look at the source code it shows url(896). We have tried selecting the image again (which shows fine in the backend) but on the frontend it's still blank with an invalid URL. Any idea how to fix that and what may have happened? TIA!

To update: this below code is what's being used to pull the featured images (with the incorrect URL):

<div class="hero homepage relative-block" style="background-image:url(<?php the_field('hero_background_image'); ?>);<?php $hero_aspect_ratio = get_field('hero_aspect_ratio'); if( $hero_aspect_ratio ) { echo "padding-top:".$hero_aspect_ratio."%;"; } ?>"></div>

EDIT:-

The following also isn't grabbing any content. Any ideas?

<div class="page-content">
        <?php get_template_part('content-block-loop'); ?>
    </div>
1
Can you share url?vadivel a

1 Answers

0
votes

Your field hero_background_image returns attachment ID instead of the URL of the image. Use wp_get_attachment_url($id) with get_field() that returns the id, instead of the_field() that outputs the value to get the URL of the attachment/image:

<div class="hero homepage relative-block" style="background-image:url(<?php  echo wp_get_attachment_url(get_field('hero_background_image')); ?>);<?php $hero_aspect_ratio = get_field('hero_aspect_ratio'); if( $hero_aspect_ratio ) { echo "padding-top:".$hero_aspect_ratio."%;"; } ?>"></div>

Possible cause: if you use some metabox/custom fields plugin as MetaBox, Toolset Types or the ACF, someone has probably changed the settings for the field, to return the ID of the attachment instead of the URL. So that might also solve the issue.