This WordPress plugin provides a Language Selector Modal compatible with WPML and Divi. It allows users to select their preferred language for the website. Once a language is selected, the modal will no longer appear for that user. The selection is stored using cookies, and the user is redirected to the corresponding language-specific URL.
-
Modal Display:
- When the user visits the website for the first time, a modal pops up, prompting them to select their preferred language.
- The modal includes a list of available languages with corresponding flags and labels.
-
Language Selection:
- Users can click on their desired language option.
- Once selected, the plugin sets the language cookie and redirects the user to the appropriate language-specific page using WPML's URL structure (e.g.,
/en,/fa,/ar).
-
Cookie Storage:
- The selected language is saved in a cookie named
selected_languagewith a default expiration period of 30 days. - This ensures that the modal will not be displayed again to the same user during this period.
- The selected language is saved in a cookie named
-
Redirection:
- After selecting a language, the user is redirected to the corresponding language-specific URL.
- Redirection works seamlessly with WPML's language switcher to maintain compatibility.
-
Skip Modal for Returning Users:
- On subsequent visits, if the cookie
selected_languageexists, the modal will not be displayed. - This allows the user to directly access the website in their preferred language.
- On subsequent visits, if the cookie
-
WPML Compatibility:
- Fully integrates with WPML, utilizing its language URLs and switcher for multilingual sites.
-
Divi Theme Compatibility:
- Designed to work smoothly with Divi and its custom layouts without breaking the site's design or functionality.
-
Automatic Language Detection:
- The plugin automatically detects whether a language has been previously selected by checking the
selected_languagecookie.
- The plugin automatically detects whether a language has been previously selected by checking the
-
Customizable Language List:
- Languages and their flags can be modified dynamically in the PHP code.
- The list is rendered automatically in the modal.
-
Seamless User Experience:
- If a language is selected, the modal is skipped on future visits.
- Redirection is handled efficiently to enhance usability.
-
AJAX Integration:
- Uses AJAX to set the language cookie without reloading the page.
-
Responsive Design:
- Fully responsive modal that adapts to different screen sizes, ensuring a consistent experience across devices.
-
PHP Code:
- Handles modal rendering, cookie management, WPML integration, and AJAX requests.
- Ensures the modal is not displayed if a cookie already exists.
-
JavaScript:
- Manages the modal's behavior, including language selection, AJAX requests, and hiding the modal for returning users.
-
CSS:
- Defines the modal's appearance and ensures it is visually appealing and responsive, even in Divi layouts.
- Download the plugin files.
- Place the files in the
/wp-content/plugins/directory of your WordPress installation. - Activate the plugin through the WordPress admin panel.
- Ensure WPML is installed and configured properly to support multiple languages.
- The plugin automatically activates the modal on the website's front end.
- No additional configuration is required unless you want to modify the language list.
-
Adding New Languages:
- Open the PHP file and modify the
$languagesarray to include new languages and their flags.
- Open the PHP file and modify the
-
Cookie Expiration:
- The cookie expiration period can be adjusted by changing the
time()value in thesetcookie()function.
- The cookie expiration period can be adjusted by changing the
-
Modal Styling:
- Update the
style.cssfile to modify the modal's appearance.
- Update the
-
Divi Adjustments:
- The plugin inherits Divi's styling by default. Additional styling can be added in
style.cssif needed.
- The plugin inherits Divi's styling by default. Additional styling can be added in
-
WPML Integration:
The plugin dynamically uses WPML's language URLs, ensuring redirection and compatibility with WPML's language switcher. -
Divi Support:
The modal is fully responsive and styled to work seamlessly with Divi's custom layouts, ensuring no disruption to the user experience.
Feel free to fork this repository and contribute to the plugin! If you encounter any issues or have feature requests, please create an issue on GitHub.
This plugin is open-source and distributed under the MIT License. You are free to use, modify, and distribute it as per the terms of the license.