We’re building a multilingual site where the client wants to be able to change a lot of text in the admin – such as buttons – rather than having it defined in the theme. We’re using ACF option pages for this.
I haven’t been able to figure out if there is a way to have a dynamic element to fields. Say we have a button that looks like this:
Back to [event category] overview page
The client wants to change the text of the button, but how can I add the dynamic variable (name of event category) in the field output? Its placement might change depending on language, so ideally I would like to write something like this in ACF admin:
Back to %s overview page
And then in the theme, do something like:
the_field('my-ACF-field-value', $my-event-category-variable);
Is this possible?
maybe
printf(get_field('my-ACF-field-value'), $my_event_category_variable);
Thanks a lot Hube2! That worked, I just needed to add the option-call and all is fine:
printf(get_field('my-ACF-field-value', 'option'), get_the_title($post->post_parent));
I thought ACF probably didn’t use %s and this wouldn’t be possible, but I’m happy I was wrong. Amazing plugin, I am continuously impressed the more I learn about it.
Actually, ACF does not handle the %s and printf stuff internally.
If we break it down to steps:
- Get your field value that contains %s
- Get the value to replace %s with
- call PHP pringf() function using the retrieved values
Aha, so it’s handled outside of ACF. But still it doesn’t stop the functionality – often I find plugins get in the way of many base functions.
Thanks again for taking the time to reply!