Home › Forums › Add-ons › Options Page › Don't translate option page
I create an option page with ACF PRO and i want that fields are avaiable in all languages.
Now i get to them with
get_field(‘name’, ‘options’)
but they arent’ displayed in translated pages.
Ty
You can make use of the acf/settings filter to reset the current language so as to return language independent theme options. The code would look like so:
// add this
add_filter('acf/settings/current_language',function() {
global $sitepress;
return $sitepress->get_default_language();
});
// this is already in your code
$my_field = get_field('my_field', 'option');
// reset to original language
add_filter('acf/settings/current_language',function() {
return ICL_LANGUAGE_CODE;
});
Hi @James,
that code should be stored in functions.php or should be every file that we use elements from options.
Thanks,
Andreas
A little addition, although it’s an older topic.
I needed this as well, but as @andreasdm mentioned already, it needs to added ‘around’ each option that you retrieve.
So I made it a bit easier, so you don’t have to add this around each get option field you use. I made a custom function (which needs to be added in functions.php) which returns the original value, based on the field name that is inputted.
/**
* Force return default language option value
*
* @param bool $field_name
*
* @return bool|mixed|null
*/
function beee_get_filtered_option( $field_name = false ) {
if ( false == $field_name ) {
return $field_name;
}
/**
* Set language to default
*
* @return bool|mixed
*/
function beee_set_default_lang() {
global $sitepress;
return $sitepress->get_default_language();
}
add_filter( 'acf/settings/current_language', 'beee_set_default_lang' );
// retrieve $field_name option value
$value = get_field( $field_name, 'option' );
/**
* Reset to 'real' language
*
* @return mixed
*/
function beee_reset_to_real_lang() {
return ICL_LANGUAGE_CODE;
}
add_filter( 'acf/settings/current_language', 'beee_reset_to_real_lang' );
return $value;
}
if ( class_exists( 'acf' ) ) {
add_action( 'init', 'sd_get_filtered_option' );
}
Add this as is. No changes needed.
Then call each option value like this:
beee_get_filtered_option( $option_field_name );
The topic ‘Don't translate option page’ 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.