Advanced Custom Fields and Polylang
-
Hi there!
Does Polylang support Advanced Custom Fields plugin? I’ve installed it in my site but I cannot translate custom fields.
Thank you for you time.Alessandro
-
Hi
Yes it supports Advanced Custom Fields, I use it on my website.Have you looked at this document? https://polylang.pro/doc/function-reference/
Have you registered the the strings in functions.php file first?
It should look like this:
add_action('init', function() { if (function_exists('pll_register_string')) { pll_register_string('Your String', 'Your String'); } });Then open String Translations in WordPress Dashboard and you should see your new registered strings. You then have to add the translation for ‘Your String’.
You then need to add the custom fields to your template file in order to get the values.
I hope this helps.
Morris
Hi Morris and thank you for your answer.
I’ve created my own custom Field Group in ACF but I cannot understand what values I have to insert instead of ‘Your String’ value you have suggested. The ACF group has a key (ie. group_5f4625bf923c8) and each custom field has a name that can be customized. What value do I have to insert?
Thank you.Alessandro
Hi
I have set up two custom fields, called description_en and description_cy, these fields are assigned to my Custom Post Type so that I can add the English version and the Welsh version on the same page, and I have registered one label in functions.php as Description.In String Translations, I would have Description in English and I would then have to get the translated word for Description. In my case the Welsh word for Description is ‘Disgrifiad’.
In my one page template I would need to retrieve the values for the custom fields and the label for Description as a variable.
My code I am using is to test to see if the HTML page is for English or my other language Welsh, so I am only going to be using one template here:
$description = pll__('Description'); /* Description Label */ if(get_locale() == 'en_GB') : if(get_field('description_en')) { echo '<p><strong>' . $description . ':</strong><br> ' . get_field('description_en') . '</p>'; } else { echo '<p><strong>' . $description . ':</strong> Not Entered</p>'; } endif; if(get_locale() == 'cy') : if(get_field('description_cy')) { echo '<p><strong>' . $description . ':</strong><br> ' . get_field('description_cy') . '</p>'; } else { echo '<p><strong>' . $description . ':</strong> Ddim yn hysbys</p>'; } ?> endif;In my 1 page template I have tested to see if my page is in English or Welsh and then whatever page I am on, I should get the correct translation.
If I am using 2 templates then I wouldn’t need to do the check for ‘get_locale()’, I would just insert the code as is but any labels or text would then have to be translated.
English Page Template
if(get_field('description_en')) { echo '<p><strong>' . $description . ':</strong><br> ' . get_field('description_en') . '</p>'; } else { echo '<p><strong>' . $description . ':</strong> Not Known</p>'; }Welsh Page Template
if(get_field('description_cy')) { echo '<p><strong>' . $description . ':</strong><br> ' . get_field('description_cy') . '</p>'; } else { echo '<p><strong>' . $description . ':</strong> Ddim yn hysbys</p>'; }I hope this makes sense…
Morris
Hi Morris and thank you for your deep explanation.
I’m not a coder and so I don’t know if I will be able to apply your solution.
Thanks anyway.Regards
The topic ‘Advanced Custom Fields and Polylang’ is closed to new replies.