Last active
          April 20, 2020 09:28 
        
      - 
      
- 
        Save mahbubur001/1b7621e521e4cb74d5c786c30e91523c to your computer and use it in GitHub Desktop. 
Revisions
- 
        mahbubur001 revised this gist Apr 20, 2020 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,8 @@ <?php /* * https://wpml.org/wpml-hook/wpml_active_languages/ */ function press_wpml_language_selector() { if (!is_front_page() && is_home()) { $url = get_post_type_archive_link('post'); 
- 
        mahbubur001 created this gist Apr 20, 2020 .There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ <?php function press_wpml_language_selector() { if (!is_front_page() && is_home()) { $url = get_post_type_archive_link('post'); $output = ''; $langs = [ [ 'url' => apply_filters('wpml_permalink', $url, 'en'), 'name' => 'English' ], [ 'url' => apply_filters('wpml_permalink', $url, 'zh-hans'), 'name' => '中文' ], [ 'url' => apply_filters('wpml_permalink', $url, 'pa'), 'name' => 'Punjabi' ] ]; foreach ($langs as $lang) { $output .= sprintf('<li class="press-wpml-swatch"><a class="wpml-ls-link" href="%s"><span class="wpml-ls-native">%s</span></a></li>', $lang['url'], $lang['name']); } } else { $output = ''; $languages = icl_get_languages('skip_missing=0&orderby=DIR'); if (!empty($languages)) { foreach ($languages as $language) { if ($language['active']) { continue; } $output .= sprintf('<li class="press-wpml-swatch"><a class="wpml-ls-link" href="%s"><span class="wpml-ls-native">%s</span></a></li>', $language['url'], $language['code'] === 'zh-hans' ? '中文' : $language['native_name'] ); } } // echo "<pre>"; // print_r($languages); // echo "</pre>"; // $output = ''; // ob_start(); // do_action('wpml_add_language_selector'); // $wpml_items = ob_get_clean(); // if ($wpml_items) { // $wpml_items = str_replace('简体中文', '中文', $wpml_items); // $regex = '#\<a href="([^"]*)".*?\>(.+?)\<\/a\>#s'; // preg_match_all($regex, $wpml_items, $res, PREG_SET_ORDER); // if (!empty($res)) { // foreach ($res as $item) { // if (strpos($item[0], "한국어") === false) { // $output .= sprintf('<li class="press-wpml-swatch">%s</li>', // $item[0] // ); // } // } // } // // } } return $output; }