Last active
May 13, 2025 10:53
-
-
Save a11smiles/0d6694557a06fbffb9c5bc7425561822 to your computer and use it in GitHub Desktop.
Revisions
-
a11smiles revised this gist
May 13, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -31,7 +31,7 @@ function translate_shortcode( $atts = [], $content = null, $tag = '' ) { //display url for language $translated_url = $wg_url->getForLanguage( $language ); if ( ! is_null($translated_url) ) { $o = '<a href="' . $translated_url . '" class="lang-link" data-wg-notranslate>' . $custom_atts['label'] . '</a>'; set_transient(get_the_guid() . '__' . $custom_atts['lang'], $o, $cache_timeout); -
a11smiles revised this gist
May 12, 2025 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,4 @@ function translate_shortcode( $atts = [], $content = null, $tag = '' ) { // Get current URI and set cache timeout $current_url = $_SERVER["REQUEST_URI"]; $cache_timeout = 86400; -
a11smiles revised this gist
May 12, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ function translate_shortcode( $atts = [], $content = null, $tag = '' ) { $o = null; // Get URL from cache if possible if ( false === ( $o = get_transient( get_the_guid() . '__' . $custom_atts['lang'] ) ) ) { $language_services = weglot_get_service( 'Language_Service_Weglot' ); $request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' ); -
a11smiles revised this gist
May 12, 2025 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -16,10 +16,9 @@ function translate_shortcode( $atts = [], $content = null, $tag = '' ) { ), $atts ); $o = null; // Check URL from cache if possible if ( false === ( $o = get_transient( get_the_guid() . '__' . $custom_atts['lang'] ) ) ) { $language_services = weglot_get_service( 'Language_Service_Weglot' ); $request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' ); -
a11smiles revised this gist
May 12, 2025 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ function translate_shortcode( $atts = [], $content = null, $tag = '' ) { global $wp_query; // Get current URI and set cache timeout $current_url = $_SERVER["REQUEST_URI"]; $cache_timeout = 86400; // normalize attribute keys, lowercase -
a11smiles revised this gist
May 12, 2025 . No changes.There are no files selected for viewing
-
a11smiles revised this gist
May 12, 2025 . No changes.There are no files selected for viewing
-
a11smiles created this gist
May 12, 2025 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ function translate_shortcode( $atts = [], $content = null, $tag = '' ) { global $wp; global $wp_query; $current_url = home_url(add_query_arg(array(), $wp->request)); $cache_timeout = 86400; // normalize attribute keys, lowercase $atts = array_change_key_case( (array) $atts, CASE_LOWER ); // override default attributes with user attributes $custom_atts = shortcode_atts( array( 'lang' => 'en', 'label' => 'English', ), $atts ); // Get URL from cache if possible $o = null; // Check if URL was found if ( false === ( $o = get_transient( get_the_guid() . '__' . $custom_atts['lang'] ) ) ) { $language_services = weglot_get_service( 'Language_Service_Weglot' ); $request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' ); if ( ! is_null($language_services) && ! is_null($request_url_services) ) { //create url object $wg_url = $request_url_services->create_url_object( $current_url ); // get a language $language = $language_services->get_language_from_internal($custom_atts['lang']); //display url for language $translated_url = $wg_url->getForLanguage( $language ); if (!is_null($wg_url)) { $o = '<a href="' . $translated_url . '" class="lang-link" data-wg-notranslate>' . $custom_atts['label'] . '</a>'; set_transient(get_the_guid() . '__' . $custom_atts['lang'], $o, $cache_timeout); } } } // return output return $o; } function translate_shortcode_init() { add_shortcode( 'translate', 'translate_shortcode' ); } add_action( 'init', 'translate_shortcode_init' );