Support

Account

Home Forums Front-end Issues How can I apend code before and after image?

Solving

How can I apend code before and after image?

  • I have a custom image field that I am trying to insert into a custom Visual Composer module that someone wrote for me. The problem is that instead of the image showing in my front end it simply returns the text value of the image (Image Object, Image URL, or Image ID).

    Unfortunately the developer is not available so I am trying to figure out on my own how I wrap the custom field in the necessary code that will allow to show on my page and also how can I tell WP to display a specific thumbnail size for the image?

    If I change the field type to a WYSIWYG field and insert the image it works but I was hoping to use standard image field so the user’s GUI is not cluttered with unnecessary information or options.

  • Hi Lazlo

    This code should help you out if you are returning an image url

    <img src="<?php the_field("image"); ?>" alt="">

    Replace image with the field name that the image is stored in.

    If you want to get a specific image image then set the following options.

    Return an “image object” to the front end when the field is called
    The image object option will return different properties and image sizes for the image uploaded. The image sizes can be accessed using the following

    <?php
      $image = get_field("image");
      $image = $image["sizes"]["image_size"];
    ?>
    <img src="<?php echo $image; ?>" alt="">

    Replace “image_size” with the image size name that you would like to show. If you do not know the name of the image sizes, use the following and then take the name from it.

    <?php
    $image = get_field(“image”);
    print_r($image[“sizes”]);
    ?>

  • Thank you very much for your reply. I will try that right now and see if I can get it to work.

  • This reply has been marked as private.
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.