We recently encountered a seemingly unsolved problem while building a multilingual site with The7 WordPress theme.
The problem: The way the text on the header search widget is set, it is not registered as a string, and cannot be translated using WPML string translation. See this thread for more details.
Our client absolutely wanted to keep the same functionality in all languages, so hiding the text was not an option.
We came up with a simple script as a solution.
Since our clients’ primary site is in French, and the string is defined in french in the theme options, this code is designed to run when the detected site language is english. It can be adapted to work for any language, by changing the ICL language paramater in the if statement.
Before starting, please make sure to have a full back up of all your website files AND database. This script should not affect anything, however we are not responsible for any data loss, and recommend being able to quickly revert back.
Secondly, please make sure you are running the7 theme on WordPress, with a child theme.
Make sure you:
1 – Have a full backup of your websites files and database
2 – Are running the7 theme with an active child theme
Step 1
Copy the below code and save it within your child theme folder as dt7-lang-script-prog.js
On the line that says $('#trigger-overlay').html('YOUR_TEXT');
change the ‘YOUR_TEXT’ to the text you want displayed.
// JavaScript Document
//Change the search bar text for The7 theme
// Author: Progressive Web Solutions
//Author URL: https://progressivewebsolutions.ca
//Version 0.2
//October 28th 2018
jQuery(function ($) {
$(document).ready(function(e) {
$(‘#trigger-overlay’).html(‘YOUR_TEXT’);
$( “#phantom #trigger-overlay” ).html(‘YOUR_TEXT’);
});
});
Step 2
Add this code to your functions.php file in your child theme.
In the first line, change the language code to your secondary language.
In the third line, change YOURDOMAIN.COM to your domain.Change YOUR_CHILD_THEME to the folder that contains the files for your child theme. Lastly change JS_FILE_LOCATION to the location within your child theme folder where you are saved the file from step 1.
if (ICL_LANGUAGE_CODE=='en'){
function change_dt7_search_string() {
wp_enqueue_script( 'change-dt7-search-string', 'https://YOURDOMAIN.COM/wp-content/themes/YOUR_CHILD_THEME/JS_FILE_LOCATION/dt7-lang-script-prog.js', array( 'jquery' ), '0.1', 'true');
}
add_action( 'wp_enqueue_scripts', 'change_dt7_search_string' );
}