Wordpress: Polylang and ACF Options page on ajax calls takes default language value - wordpress

I'm working on a website, which is multilingual.
We're using Polylang and the ACF custom fields plugin.
Works fine in general, the issue is with the ACF Option pages.
The option pages are translated also in different languages.
The content we are taking from there is being displayed according to translation - in english on the english version of a page, french on the french etc.
The problem: We have a contact us form, where we take the recipients email address from the ACF option pages.
(We want to send it to a different recepient when its a different language.)
Here it always takes the email address from the default language option page and I don't understand why.
We are taking the email recipient for the ajax call with get field command, like on pages displaying content:
get_field('service_email', 'option' );
Anyone got an idea what could cause this? Or where to look?

In the end we found the solution. It took a bit of digging, but I hope this helps if anyone encounters the same issue.
We needed to add the following setup in the functions.php of our theme to have the ACF options pages also translated for the each language:
// Translating Options Page Compatibility
// add filter with the path to your acf installation
add_filter('acf/settings/default_language', 'my_settings_default_language');
add_filter('acf/settings/current_language', 'my_settings_current_language');
function my_settings_default_language( $lang ) {
if($lang == "") {
$lang = pll_default_language(); // pll_ is a polylang function
}
return $lang;
}
function jfrog_settings_current_language( $lang ) {
$lang = pll_current_language();
return $lang;
}
Side Note: We're using a theme installed version of ACF.
hope this helps, Cheers

Related

WPML language switcher. Link to custom page when no translation

I have a question. I am using WPML plugin. In WPML->languages->Language switcher options i checked "Link to home of language for missing translations". Now when i click language switcher country flags and translation is missing it will redirect to homepage. My question is how to redirect to custom page when translation is not found. I want to create page with text "Sorry translation is missing. Please contact us for more info..."
Thank you for your time
First make sure you have WPML->languages->Language switcher options "Link to home of language for missing translations" checked. Then create your custom translation not found page in main language and translate it to other languages using WPML. Then add this code to your functions.php
add_filter('wpml_ls_language_url', 'redirect_link',10,2);
function redirect_link($url,$lang){
if($lang['missing'] == 1) {
$permalink_to_translation_not_found_page_in_main_language = get_the_permalink(40); //40 is page id of a custom translation not found page in main language
$lang['url'] = apply_filters( 'wpml_permalink', $permalink_to_translation_not_found_page_in_main_language , $lang['language_code'] );
}
return $lang['url'];
}
I hope this is useful for someone

Woocommerce mini-cart language keeps showing the same default language

I have been trying to change the language of mini cart without success. It keeps showing the same default set language, even though I choose a different language using polylang.
I have tried the below code in functions.php, but it keeps returning the same French version of the page.
function modify_cart_url($wc_get_page_permalink) {
$setLocale = pll_current_language();
echo $cart_page_id = pll_get_post(2374,"$setLocale");
$wc_get_page_permalink = get_permalink($cart_page_id);
return $wc_get_page_permalink;
}
add_filter( 'woocommerce_get_cart_url', 'modify_cart_url',10, 1);
2374 is the page ID of the French cart page.
So in case if anyone facing the same problem,
You can copy the complete woocommerce - mini-cart.php code inside the header.php of your theme.
After that you can get the correct locale set whenever you change the language using polylang.
And the get the cart page url of that particular language.
$curr_set_lan =get_locale();
$woo_cart_page_id = get_option( 'woocommerce_cart_page_id' );
the_permalink(pll_get_post($woo_cart_page_id, $curr_set_lan));

WPML same slug(url) different language

I have this site :
example.com/watches (watches is a custom post type)
There are two available languages : EN(default language), GR.
When i change to GR (while on page example.com/watches)
it redirects to example.com/el/watches which is right.
When i am on example.com/watches/rolex and i try to change language it redirects to example.com/el/taxwatches/rolex-el but i want it just to be example.com/el/watches/rolex/.
taxwatches is my custom taxonomy.
rolex-el is the slug of the term inside that taxonomy.
Has anyone experienced an issue like this before?
I've tried to save the permalinks again and check my WMPL settings but i can't see something wrong.
EDIT 1 : If i manually go to example.com/el/watches/rolex it will work fine.
Both example.com/el/watches/rolex and example.com/el/taxwatches/rolex-el work.
EDIT 2: From what i understand WPML takes the slugs, is there a way to change it so it takes the names?
Ok so for anyone having problems with multi language sites - but want to have the "same slugs" in the urls (will never be same slugs - but going to look like that) read the below.
WPML uses slugs which are created from the wordpress core structure - you can't have two slugs with the exactly same name. If default language is EN and you have a secondary, in my case GR, then one slug is going to be "myslug" and the other "myslug-gr" (you can customize this "-gr" through WPML settings).
In functions.php you can filter the "wpml_ls_filter" function which is fired when your Language switcher is created.
Code as below :
add_filter('icl_ls_languages', 'wpml_ls_filter');
function wpml_ls_filter($languages) {
foreach ($languages as $lang_code => $language) {
$mTempString = $languages[$lang_code]['url'];
echo $mTempString; // HERE
// If "tax" is found in that string, replace it with "" - remove it.
if (strpos($mTempString, "tax") !== false) {
$languages[$lang_code]['url'] = str_replace("tax", "", $mTempString);
}
}
return $languages;
}
The above echo is going to show you the url that is created (and you can manipulate it) of each language button when pressed whenever you visit a page/post.
I haven't wrote a complete solution because that really depends on what you want to do. For example the above code helped me achieve to remove "tax" if found in the url.
This answer is providing an alternative way to achieve multiple languages with same slug
Polylang with Polylang Slug these 2 plugins can do
https://wordpress.org/plugins/polylang/
https://github.com/grappler/polylang-slug/
You can use my plugin, it is based on the newest Polylang Pro module and does what you need: https://github.com/lufton/polylang-share-slug

wordpress blog basepath

im working on a wordpress blog tryin to develop a multilanguage system.
Whenever the user clicks on his language button the lang query parameter is added to the url
Ex. localhost/my-blog?lang=es
Everything works.The point is i have the blog main menu that has links to different sections of the site that are using the wordpress bloginfo('url') :
Ex. contact us
And whenever the user choose it's language at the home-page and then clicks on "contact us"
he receive this wrong link:
localhost/my-blog?lang=es/contact-us
which wordpress function you use guys for this kind of things?
thanks
Luca
I think this type of url query will get you into trouble in the future, why not conform to using either a session value or base cookie to store the users choice,
then that way you can simply add some code to your functions.php file to read the session value or cookie, and return the translation type?
there is also this plugin xili-language
ie: functions.php
// START THE SESSION
function start_session(){
session_start();
}
add_action('init', 'start_session', 1);
function set_lang_pref($lang_pref){
if(isset($_GET['lang']) && ($_GET['lang']!=''){
$setlang = $_GET['lang'];
switch($setlang){
case "es" :
$lang = "es_ES";
$_SESSION['selectedlanguage']=$lang;
break;
}
}else{
return false;
}
}
the code is really rough, but you get the idea..?
store the users choice,
check for that choice,
if its been set then use that value as the language pref on the site..?
else just revert back to the default..

WordPress ShortTag Custom Variable

I like to have a whole website build in wordpress. All through the site there will be telephone number, address, some link here and there...
I like to be able to defin variable shorttag in the admin panel somewhere, and be able to insert it in the WYSIWYG like that :
you can contact us anytime [phone] or visit us here : [address]
so changing addres or number is a snap !
any idea, i got http://wordpress.org/extend/plugins/custom-configs/screenshots/ but need to insert in php not shorttag...
You can use the do_shortcode() function to output the shortcode values using php. Assuming that
Example:
<? echo do_shortcode('[phone]'); ?>
Using your plugin is easy to define shortcodes that are outputting the content of a custom setting
function get_phone($atts, $content = null) {
return get_config('phone-settings');
}
add_shortcode('phone', 'get_phone');
Assuming that in your plugins, you have defined a custom settings with the key phone-settings

Resources