Home › Forums › General Issues › Strings in the_field
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:
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!
The topic ‘Strings in the_field’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.