This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
Tagged: Not WPML issue
This topic contains 7 replies, has 2 voices.
Last updated by Waqar Ali 1 year, 6 months ago.
Assisted by: Waqar Ali.
Author | Posts |
---|---|
June 17, 2023 at 9:45 am #13843541 | |
joniN |
Hi, i have written text content into my Shortcoder plugin. Same texts are used in multiple woocommerce product pages. Texts are called like [sc name="borofloat"][/sc] in product pages. But those are not translated and your Themes and plugins localization cannot find those contents from inside plugin. I tried to add wpml-config.xml to get ther shortcodes automatically but it wont appear anywhere. I tried to look all your documentation and guides but did not get this working. |
June 17, 2023 at 1:28 pm #13843805 | |
joniN |
More information: How do i get the Shortcode-texts (called by like for example [sc name="borofloat"][/sc] ) show up in product page in translated language, not original? Do i need to be written in wpml-config file like i did, an did i write it correctly there? I wrote it like this: |
June 17, 2023 at 1:29 pm #13843807 | |
joniN |
More information: How do i get the Shortcode-texts (called by like for example [sc name="borofloat"][/sc] ) show up in product page in translated language, not original? Do i need to be written in wpml-config file like i did, an did i write it correctly there? I wrote it like this: |
June 20, 2023 at 4:39 am #13855355 | |
Waqar Ali |
Hi, Thank you for contacting us and I'd be happy to assist. If your shortcode is: [sc name="borofloat"][/sc] Its code in the 'wpml-config.xml' file should look like this: <wpml-config> <shortcodes> <shortcode> <tag>sc</tag> <attributes> <attribute>name</attribute> </attributes> </shortcode> </shortcodes> </wpml-config> ( ref: https://wpml.org/documentation/support/language-configuration-files/#page-builder-content ) Note: the 'attribute' should include the 'name' of the shortcode attribute (i.e. 'name') and not the passed value (i.e. 'borofloat'). I hope this helps and please let me know how it goes. regards, |
June 20, 2023 at 7:18 am #13856109 | |
joniN |
Hi, thanks for reply! Ok, i corrected the xml, but unfortunately did not get correct result. -I can manually change translated shortcode name to "borofloat"->"borofloat_en" (and other languages) and then change into translated product the shortcode manually to for example "borofloat_en", and it works but it is quite a big job as i was planned to use 5 different languages and products i have almost 100 -But should it work like i was imagined: when shortcode was added to wpml-config.xml, it should automatically take translated version of shortcode instead of original? -Or can you recommend another shortcoder what works with your translation plugin better? There is only html text inside of shortcodes. |
June 22, 2023 at 1:20 pm #13877579 | |
Waqar Ali |
Thanks for writing back. I can suggest a better alternative, but first, I'll need to see exactly how this custom shortcode is configured in the admin area. Can you please share temporary admin login details, along with the information about where this shortcode is defined and is in use? Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details. |
June 28, 2023 at 5:54 am #13906793 | |
Waqar Ali |
Thank you for waiting. After reviewing your requirements, I've got a simpler solution that will allow you to save reusable content blocks, without using the Shortcoder plugin, in a translation-friendly way. 1. From WP Admin -> Toolset -> Post Types, you can register a new custom post type and name it something like 'Contents'. In this post type, you can add each instance of reusable content that you'd like to use on Product pages or pretty much anywhere on your website. The content that you are currently saving in each shortcode, can be stored as the body/content of each post in this new post type. The translation of this content would work the same way as you translate your other posts and pages and you'll only have to do it once for each of these posts. 2. Next, to load the content from these 'Contents' posts, you can register a new custom shortcode: add_shortcode('custom-content-shortcode', 'custom_content_shortcode_func'); function custom_content_shortcode_func($atts) { $a = shortcode_atts( array( 'id' => '', ), $atts ); $target_post = apply_filters( 'wpml_object_id', $a['id'], 'content' ); $content = apply_filters( 'the_content', get_the_content(null, false, $target_post) ); $content = wptexturize( $content ); ob_start(); echo $content; return ob_get_clean(); } The above code snippet can be registered through Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) 3. To load the content from one of these posts, in any of your products, you can use this newly registered shortcode, like this: [custom-content-shortcode id='1234'] Where you'll replace, '1234' with the actual ID of the target 'Contents' post. The shortcode will automatically pick the correct translation of the content, based on the language of the current product/post/page it is being used on. I hope this helps and please let me know if you need further assistance. |