Home Forums General Issues image field as a loop function


image field as a loop function

  • Hello,
    I wanted to display an image that is in a wordpress loop, which is also a function. Unfortunately, I have to do this without the <?php and ?> tags. It doesn’t work, I don’t know how to do it. And it would be best if the “return $name;” works, otherwise the shortcode will not be displayed correctly 🙁

    plase help me !

  • Hey @johnykalesony,

    It’s not the most descriptive question so there’s some guesswork on my part. I’m assuming your image field is returning an array as opposed to an ID or a URL.

    function my_custom_gallery() {
            'post_type' => 'galeria',
            'orderby' => 'publish_date',
            'order' => 'ASC'
        while (have_posts()) : the_post();
            $image_field = get_field('image_field');
            $image_url = $image_field['url'];
            $image_alt = $image_field['alt']; ?>
            <img src="<?php echo esc_url($image_url); ?>" alt="<?php echo esc_attr($image_alt); ?>" />
        <?php endwhile;
    add_shortcode('mygallery-1', 'my_custom_gallery');

    I hope this helps!


Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.