Language Selector Styling
Adding your own CSS code or HTML button
Override language selector CSS
You can add your own CSS rules to customize the language button. Weglot automatically adds a button to your page, which is either a dropdown or a list and looks like this:
<aside data-wg-notranslate class="country-selector weglot-dropdown weglot-default weglot-invert">
<input id="weglot_choice" type="checkbox" name="menu">
<label for="weglot_choice" class="wgcurrent wg-li weglot-flags flag-0 en" data-code-language="en">
<span>EN</span>
</label>
<ul>
<li class="wg-li weglot-flags flag-0 fr" data-code-language="fr">
<a data-wg-notranslate href="http://example.com/">FR</a>
</li>
</ul>
</aside><aside data-wg-notranslate class="country-selector weglot-inline weglot-default weglot-invert">
<input id="weglot_choice" type="checkbox" name="menu">
<label for="weglot_choice" class="wgcurrent wg-li weglot-flags en" data-code-language="en">
<span>English</span>
</label>
<ul>
<li class="wg-li weglot-flags fr" data-code-language="fr">
<a data-wg-notranslate href="http://example.com/fr/">Français</a>
</li>
</ul>
</aside>You can use these classes to add your own rules. For example, add this in "Override CSS" to make the language name uppercase:
.country-selector a {
text-transform: uppercase;
}Override CSS on the WordPress back office
You can add your custom CSS rules directly from your WordPress back office. To do that, log in to your WordPress and go to: Weglot > Language button design (Optional) > Override CSS
Override CSS using a WordPress hook
This filter lets you add custom CSS by default, without going through the settings.
Don't load the Weglot CSS file
By default, the Weglot plugin loads the stylesheet /wp-content/plugins/weglot/dist/css/front-css.css. If you would prefer not to load it, you can dequeue it with the wp_enqueue_scripts action:
Override the language selector HTML markup
The Weglot plugin exposes a filter that lets you modify the HTML structure of your language-switch button. See the reference: weglot_button_html.
Hook parameters
$button_html: string containing the switcher's HTML before it is rendered.$add_class: string containing the classes (space-separated) related to the switcher's layout context and options.
Example: add code before/after the button
The example below adds HTML before and/or after the button (you can also run preg_replace() on the selector's HTML).
Example: rebuild the language selector from scratch
If you'd like to make major changes to the HTML structure of your language button, you can start from the code below.
Change the language selector title
If you use the language selector in a menu with the "dropdown" option enabled, the title of the selector in the menu is "Choose your language" in English. To change this text, edit the plugin's translation files, or use the following hook:
Add the current-menu-item class to the selector in a menu
If you use the language selector in a menu and want the current-menu-item class to be present on the current page's link in the selector, use the weglot_active_current_menu_item filter:
Last updated