Support

Account

Home Forums General Issues show custom field for media (img) in theme Reply To: show custom field for media (img) in theme

  • To use it in a theme you can just do

    $img = get_field('image_source');
    echo "<img src='" . $img['url'] . "' alt='" . $img['alt'] . "'>";

    You can replace (or add srcset attributtes) by replacing $img['url'] with $img['sizes']['large'], $img['sizes']['small'], etc.

    If you wanted to use it actually in a post (as in within the WP editor), your best bet would likely be to create a shortcode in your theme’s functions.php, which I expect would look something like the following:

    function acf_image_function($atts) {
        $img = get_field($atts[0]);
        echo "<img src='" . $img['url'] . "' alt='" . $img['alt'] . "'>";
    }
    add_shortcode('acf_image_shortcode', 'acf_image_function');

    EDIT: then you’d use the shortcode [acf_image_shortcode image_source]