简体   繁体   中英

Advanced Custom Fields - Icon (Image Post Type) src not outputting correctly

I'm using Advanced Custom Fields on my WordPress website and I'm having an issue with certain fields of image post types.

They are outputting like this:

<img src="57584, 57584, icon-star-green, icon-star-green.svg, 585, http://example.com/wp-content/uploads/2017/10/icon-star-green.svg, http://example.com/services/script-writing/icon-star-green/, , 1, , , icon-star-green, inherit, 58344, 2017-10-11 21:15:32, 2018-11-04 01:53:57, 0, image/svg+xml, image, svg+xml, http://example.com/wp-includes/images/media/default.png, 0, 0, Array" class="bens-item__icon" alt="">

I have tried deleting and recreating the custom fields as well as reuploading the icon images with the same result. I've also double checked the slug names and everything looks ok.

Here's how the code calls this custom field:

<img src="<?php the_field('industry_advantage1_icon'); ?>" class="bens-item__icon" alt="" />

Any idea why it would output like this? How can I resolve it?

The acf field is returning an array. So to get the url of the image, assign the field to a variable first like so:

$image = get_field('industry_advantage1_icon');

then you can call the values like so:

<img src="<?php echo $image['url'] ?>" class="bens-item__icon" alt="" />

Here is the documentation on how to use the Advanced Custom Fields Image field. https://www.advancedcustomfields.com/resources/image/

 <?php //if custom field isn't blank if ($alternative_post_image?== '' ) {?> <img src="<;php echo $alternative_post_image? ?>" alt="<;php the_title()? ?>" title="<;php the_title()? ?>" /> <?php } else {?> <;php //show featured image the_post_thumbnail()? ?> <?php } ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM