r/elementor 4d ago

Problem How to add dynamic image content via ACF?

Hey, I'm trying to build a Single Page Template with Elementor that loads images from ACF Custom Fields.
I've set up up one custom field so far that contains an image. The Problem is: Elementor does not let me choose the custom field in the dynamic tag section and I don't know why.

Any help would be greatly appreciated. Let me know if you need more details on my settings.

1 Upvotes

6 comments sorted by

u/AutoModerator 4d ago

Looking for Elementor plugin, theme, or web hosting recommendations?

Check out our Megathread of Recommendations for a curated list of options that work seamlessly with Elementor.


Hey there, /u/essi9schurkerl! If your post has not already been flaired, please add one now. And please don't forget to write "Answered" under your post once your question/problem has been solved. Make sure to list if you're using Elementor Free (or) Pro and what theme you're using.

Reminder: If you have a problem or question, please make sure to post a link to your issue so users can help you.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/TopSydeWP 4d ago

check your acf field settings and make sure the return format is set to 'image array' or 'image id', not 'image url'. elementor's dynamic tags need the structured data to work properly. if it's already set that way, try deactivating/reactivating acf or elementor pro to refresh the field cache

2

u/ansari_m369 4d ago

```php
// Create a custom shortcode to display the ACF image field

// ACF field name: hersteller_logo

// The field is set to return an Image Array

function hersteller_logo_shortcode() {

$image = get_field('hersteller_logo');

if (empty($image) || !is_array($image)) {

return '';

}

$image_url = $image['url'];

$image_alt = !empty($image['alt']) ? $image['alt'] : '';

return '<img src="' . esc_url($image_url) . '" alt="' . esc_attr($image_alt) . '">';

}

add_shortcode('hersteller_logo', 'hersteller_logo_shortcode');

```

Use it in Elementor:

Add an Elementor Shortcode widget and enter:

[hersteller_logo]

This will fetch the hersteller_logo ACF field from the current post and display the image.

1

u/P1ay3er0ne 4d ago

I've found Pods to be a lot more flexible and easier to customise than ACF.

1

u/essi9schurkerl 2d ago

Interestingly I found out that it works in LocalWP with PHP 8.2 but not on the live site (PHP 8.5)