Problem:
The issue here is that the user wanted to get the language of a specific post as well as the Language of the current page on the frontend.
Solution:
This can be done by using the shortcodes below.
// Add Shortcode function get_post_language( $atts ) { // Attributes $atts = shortcode_atts( array( 'id' => '', ), $atts ); $language = apply_filters( 'wpml_post_language_details', NULL, $atts['id'] ) ; return $language['language_code']; } add_shortcode( 'get_post_language', 'get_post_language' );
To get the current language being viewed you can use the shortcode below.
// Add Shortcode function current_language() { $my_current_lang = apply_filters( 'wpml_current_language', NULL ); return $my_current_lang; } add_shortcode( 'current_language', 'current_language' );
You can add them to the toolset custom code section in Toolset -> Settings -> Custom Code and activate the snippet.
The shortcodes that will be generated are
[get_post_language id='[wpv-post-id]']
And
[current_laguage]
Now for the get_post_language shortcode i'm passing in the id of a post to get the language of that post based on its ID.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Our next available supporter will start replying to tickets in about 0.69 hours from now. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | - |
- | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 14:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: America/Jamaica (GMT-05:00)
This topic contains 6 replies, has 2 voices.
Last updated by 5 years, 2 months ago.
Assisted by: Shane.