Weglot
WebsiteGithubSlack
  • Developer Documentation
  • WordPress
    • Getting Started
    • Helpers Functions
    • Hooks
      • Translations Hooks
      • Other Hooks
    • Use cases
      • Lang attribute
      • Translate link
      • Implementing Custom Link Translation
      • Wp-rocket Lazyload
      • Deactivate Weglot on Elementor
      • Weglot translate on Elementor
      • Language Selector Styling
      • Change flag size
      • Exclude a Custom Post Type
      • Exclude the search page
      • Exclude draft or private status post
      • Plugin Woocommerce: Translate all email sent to customers
      • Plugin WooCommerce: Translate Product URLs
      • Use custom language code (URL, lang and hreflang attribute)
      • Theme OceanWP: Use language selector in the main menu
      • Theme Avada: Use language selector in the main menu
      • LinkedIn Share Post: Translate oEmbed WP URL
      • Hide button on excluded page
      • Auto switch only for HomePage
      • Proxify Url
      • Translate pdf for Woocommerce pdf invoice
      • Translate pdf with Gravity pdf
      • Translate Dublin core meta (or other meta)
      • How to not translate specific ajax action
      • How to get translated url programmatically
      • How to set WP locale based on Weglot current language
      • How to translate mail from Photo Reviews for WooCommerce
      • How to translate schema from schema.org generate by Yoast plugin
      • How to translate email sending by plugin WP Mail SMTP
      • How to hide the Weglot admin button for non administrator roles
      • Exemple of snippet to translate search from JetSearch plugin
      • Example of snippet to translate your checkout element (override/added by the Funnel Builder plugin)
      • LScache
      • How to fix live builder issue with Weglot
      • Add translated url to Rankmath sitemap index
      • Advanced Woo Search X Weglot
      • Conditionally Disabling Weglot Translation for Specific URLs
    • Weglot filters
      • weglot_translate_email
      • weglot_cancel_init
      • weglot_translate_email_languages_forced
      • weglot_menu_parent_item_title
      • weglot_active_current_menu_item
      • weglot_ajax_no_translate
      • weglot_active_translation_before_process
      • weglot_active_translation_before_treat_page
      • weglot_debug_file
      • weglot_autoredirect_only_home
      • weglot_autoredirect_skip
      • weglot_remove_google_translate
      • weglot_add_hreflang
      • weglot_get_replace_modify_link
      • get_replace_modify_link_in_xml
      • weglot_get_flag_class
      • weglot_get_name_with_language_entry
      • weglot_get_class_dropdown
      • weglot_button_html
      • weglot_get_dom_checkers
      • weglot_replace_div_id
      • weglot_replace_weglot_menu
      • weglot_render_default_button
      • weglot_render_switcher_editor_button
      • weglot_href_lang
      • weglot_get_options_from_cdn_cache
      • weglot_get_options_from_cdn_cache_duration
      • weglot_get_slugs_from_cache
      • weglot_get_slugs_cache_duration
      • weglot_exclude_blocks
      • weglot_exclude_urls
      • weglot_get_parser_ignored_nodes
      • weglot_navigator_language
      • weglot_url_auto_redirect
      • weglot_replace_url
      • weglot_replace_link
      • weglot_ajax_replace_urls
      • weglot_proxify_urls
      • weglot_add_json_keys
      • weglot_json_treat_page
      • weglot_html_treat_page
      • Copy of weglot_xml_treat_page
      • weglot_render_dom
      • weglot_default_current_language_empty
    • Algolia integration
  • Proxy
    • Headers
  • Javascript
    • Getting Started
    • Options
    • Javascript functions
    • Language link Hooks
    • Translate iframe
    • Advanced concepts
      • Translation engines
  • CMS Specific
    • Shopify
  • API
    • Reference
  • Cookies
Powered by GitBook
On this page
  • Introduction
  • Getting started
  • Plugin settings
  1. WordPress

Getting Started

Starting with the Weglot WordPress plugin

PreviousDeveloper DocumentationNextHelpers Functions

Last updated 2 months ago

Introduction

Weglot has built a powerful WordPress plugin that integrates in your WordPress website and make it multilingual in a few minutes.

What does Weglot plugin do exactly ?

  1. It creates URL for each languages, like /fr/about/ or /es/about/ for instance (but doesn't create actual pages in WordPress backend)

  2. On these URL, it returns the translated content

  3. It adds a language button on the page and the hreflang tags in the <head> section of your page for SEO.

Getting started

To start, install plugin directly from the directory.

In the settings page, configure the 3 mandatory settings :

  • API Key : You get an API key in your account. If you don't have one, you can .

  • Original Language : The original language of your WordPress website.

  • Destination Languages : The languages you want your website to be translated into.

Save the settings and you are done. You will see the language button appear on your website.

Plugin settings

Exclude URL

By default, all pages are translated. You can use this field to enter URL that you don't want to translate. This field is flexible, you can exclude exact URL, or URL that contains some words or matches some regex

Another example, if you want to only translate your homepage, meaning you want to exclude every URL except / , you would use the "Match regex" and enter the following : [^/]

Exclude blocks

By default, everything is translated inside a page. But sometimes, you don't want to translate part of your page. For example all product descriptions or a customer review area.

You can add any CSS selector in the field "Exclude blocks" and it will add an attribute data-wg-notranslate on this HTML element. Everything inside this element won't be translated.

For example, if you enter this : .product-description , then your translated page will be :

<h1 class="product-title">Mon super article</h1> <!--The title is being translated-->
<p class="product-description" data-wg-notranslate>My awesome article</p><!--The description is not being translated because you excluded class product-description -->

Whitelist blocks

As mentioned before, by default everything is translated inside a page. However, you can use the exclude blocks feature to prevent translating certain parts of a page. But sometimes you may have more than just blocks on a page that you want to leave untranslated and in this instance you're unable to manipulate the dom (by adding some class for example). In this case, it's easier to only translate some part of your page.

<h1 class="product-title">Mon super article</h1> <!--The title is being translated-->
<p class="product-description" data-wg-notranslate>My awesome article</p><!--The description is not being translated because it's not on our whitelist -->
<p class="product-description-1" data-wg-notranslate>My awesome article</p><!--The description is not being translated because it's not on our whitelist -->
<p class="product-description-2" data-wg-notranslate>My awesome article</p><!--The description is not being translated because it's not on our whitelist -->
<p class="product-description-3" data-wg-notranslate>My awesome article</p><!--The description is not being translated because it's not on our whitelist -->

In this example we want to only translate the element with the class .product-title.

To do that you can exclude product-description, .product-description-1, .product-description-2, .product-description-3 class but in this case, it's easier to say to Weglot to only translate the .product-title class

To do that you can use this filter:

add_filter('weglot_parser_whitelist', 'custom_whitelist', 10, 1);
function custom_whitelist($whitelist){
	$whitelist[] = '.product-title';
	return $whitelist;
}

You can add more than one of the blocks on the whitelist array. For example if I decide to translate the block .product-description the filter will be

add_filter('weglot_parser_whitelist', 'custom_whitelist', 10, 1);
function custom_whitelist($whitelist){
	$whitelist[] = '.product-title';
	$whitelist[] = '.product-description';
	return $whitelist;
}

When the whitelist is active on a page the wg-mode-whitelist attribute is added to the body tag.

Weglot Translate
create your account