function uls_language_selector_shortcode($atts) { extract(shortcode_atts(array('url' => null, 'type' => 'links', 'url_type' => 'prefix', 'only_language' => true, 'class' => null), $atts)); //if URL is null, then it uses the current URL if (null == $url) { $url = uls_get_browser_url(); } if ("false" == $only_language) { $only_language = false; } return uls_language_link_switch($url, $url_type, $type, $only_language, $class); }
function head_reference_translation() { //get the id of the current page $url = isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on" ? "https://" : "http://"; $url .= $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; $post_id = url_to_postid($url); // get all available languages $languages = uls_get_available_languages(); $curren_code = uls_get_user_language(); // get current language // delete the current language site $code_value = array_search($curren_code, $languages); unset($languages[$code_value]); // build the url to be tranlation $url = ''; // get url from where it's using if (is_home()) { $url = get_home_url(); } else { if (is_archive() || is_search() || is_author() || is_category() || is_tag() || is_date()) { $url = uls_get_browser_url(); } } // get browser url // if exits the url so, translate this if (!empty($url)) { // use all available languages and get the url translation foreach ($languages as $language => $code) { $translation_url = uls_get_url_translated($url, $code); echo '<link rel="alternate" hreflang="' . substr($code, 0, 2) . '" href="' . $translation_url . '" />'; } } // build url to the home if (!empty($post_id) && empty($url)) { // change the filter global $uls_permalink_convertion; $uls_permalink_convertion = false; // use all available languages and get the url translation foreach ($languages as $language => $code) { // get the post_id translation if the current page has translation $translation_id = uls_get_post_translation_id($post_id, $code); if (!empty($translation_id)) { $translation_url = uls_get_url_translated(get_permalink($translation_id), $code); echo '<link rel="alternate" hreflang="' . substr($code, 0, 2) . '" href="' . $translation_url . '" />'; } } // leave the global car like it was before $uls_permalink_convertion = true; } }