add_action( 'wp_footer', 'forminator_preload', 20 ); function forminator_preload() { global $post; if ( ! $post instanceof…
Custom Language Switcher for Translatepress
// Get out of my page!
wp_dequeue_style('trp-language-switcher-v2-css');
wp_dequeue_script('trp-language-switcher-js-v2-js');
//add Language Switcher to mobile menu top
add_action( 'wpex_hook_mobile_menu_toggle_top', function() {
/*$languages = trp_custom_language_switcher(); print_r($languages);*/
echo '<div class="lang" data-no-translation>'.do_shortcode('[link_for_lang lang="en_US" label="EN"]').' | '.do_shortcode('[link_for_lang lang="de_DE_formal" label="DE"]').'</div>';
} );
/*
* Function to return the url for a particular language.
* Pass the desired language and the URL.
*/
function trpc_get_url_for_language($lang = null, $url = null) {
if ( ! class_exists('TRP_Translate_Press') )
return $url;
$trp = TRP_Translate_Press::get_trp_instance();
$url_converter = $trp->get_component( 'url_converter' );
return esc_url( $url_converter->get_url_for_language( $lang, $url, '' ) );
}
/*
* Shortcode to display the URL in another language:
* [url_for_lang lang="en_US" url="https://example.com/ro/pagina-de-test"]
*/
function shortcode_trpc_get_url_for_language($atts) {
$atts = shortcode_atts( array(
'lang' => null,
'label' => 'Translate',
'url' => get_permalink()
), $atts, 'url_for_lang' );
$url = trpc_get_url_for_language($atts['lang'],$atts['url']);
return '<a href="'.$url.'">'.$atts['label'].'</a>';
}
add_shortcode( 'link_for_lang', 'shortcode_trpc_get_url_for_language' );
// CHANGE LOGO FOR LANGUAGE
add_filter( 'totaltheme/header/logo/image_id', function( $image ) {
$url = $_SERVER['REQUEST_URI'];
if (strpos($url, '/en/') !== false) {
$image = '1130'; //change logo ID
}
// Return logo image
return $image;
} );
