For the complete documentation index, see llms.txt. This page is also available as Markdown.

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:

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.

This example mirrors the plugin's built-in button. It is a starting point — keep an eye on it across plugin updates, as the internal markup can evolve.

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:

When the auto-redirect option is enabled, the original-language link carries a wg-choose-original query parameter so visitors can reach the original language without being redirected again. If you rebuild the button yourself (see above), keep that parameter on the original-language link.

Last updated