Home › Forums › General Issues › Use ACF as multilanguage solution › Reply To: Use ACF as multilanguage solution
WPML is supposed to be the best multilingual plugin available, but like you I’m not completely sold on it.
In order to have a site with multiple languages you’ll need to have some setting that is global to tell what language the site is supposed to be displaying. I would use this variable. I would also stick with standard language codes like “en”, “fr”, “es”, etc. I would then name all of my fields consistently using that as either a prefix of suffix to my field name.
You could then create a function something like the following. This is just a quick idea. In reality I’d more than likely make this a filter or something more complicate because this does not account for all the details, but it would work.
function get_multilingual_field($field_name) {
global $language;
$value get_field($field_name.'_'.$language);
if (!$value) {
// no value returned for language
// get the default
$value = get_field($field_name);
}
return $value;
}
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.