Custom string translation wpml wordpress using php
First you need to have wordpress hosting that supports WPML such as greenbackend Unlimited and Geko Pro from here
Second, you have to define your static strings and with the associated wpml domain as following:
if ( ! function_exists( 'wpex_icl_register_strings' ) ) {
function wpex_icl_register_strings() {
// Return if function doesn't exist
if ( ! function_exists( 'icl_register_string' ) ) {
return;
}
// Array of strings
$strings = array(
'gbe_txt_about' => "About",
'gbe_tab_events' => "Events",
'gbe_tab_news' => "News",
'gbe_tab_gallary' => "Gallery",
);
// Register strings
foreach( $strings as $string => $default ) {
// print_r( $strings );
icl_register_string ( 'greenbackend', $string, $default) ;
//icl_unregister_string ( 'greenbackend', $string) ;
}
}
}
Finally, you have to call your defined strings and you could translate them from the string translation section in your wordpress dashboard.
<?php echo icl_t('greenbackend', 'gbe_tab_news', 'News');?>
<?php echo icl_t('greenbackend', 'gbe_tab_gallary', 'Gallery');?>
Leave a Reply