Support

Account

Home Forums Feature Requests Feature: the_image()

Unread

Feature: the_image()

  • Thinking, something along the lines of the_field(), where you can output a fully formed img tag without all the excess WP markup, from a ACF field

    something like this, I know it can be improved, but looking for thoughts and suggestions

    <?php if( is_numeric( get_field('image') ) ) : ?>
      <?php $theImg = wp_get_attachment_image_src( get_field('image'), 'full' ); ?>
      <img src="<?php echo $theImg[0] ?>" alt="<?php echo get_post_meta( get_field('image'), '_wp_attachment_image_alt', true); ?>" />
    <?php elseif( is_array( get_field('image') ) ) : ?>
      <?php $theImg = get_field('image'); ?>
      <img src="<?php echo $theImg['url'] ?>" alt="<?php echo $theImg['alt']; ?>" />
    <?php else : ?>
      <img src="<?php the_field('image'); ?>" alt="<?php the_title_attribute(); ?>" />
    <?php endif; ?>

    we can allow for image size (full, thumbnail) selectors and even an alt tag if one is not provided

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.