Last active
July 14, 2016 06:38
-
-
Save scrobbleme/fc87d60784e3ca39663ae323e51a1636 to your computer and use it in GitHub Desktop.
Shortcode to generate a link for a specific language for the given page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_shortcode('wpml_link', array($this, 'render_wpml_link')); | |
function render_wpml_link($attributes) { | |
$attributes = shortcode_atts( | |
array( | |
'code' => 'de', | |
), $attributes); | |
$active_languages = apply_filters( 'wpml_active_languages', null, null ); | |
if (count($active_languages) > 1) { | |
foreach ($active_languages as $language) { | |
if ($language['language_code'] == $attributes['code']) { | |
return $language['url']; | |
} | |
} | |
} | |
return get_permalink(); | |
} | |
/** | |
* Usage: | |
* | |
* [wpml_link code="de"] | |
* | |
* <a href="[wpml_link code="de"]">Deutsch</a> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment