Weglot Shortcode

Below, you’ll find a detailed guide on how to add the Weglot Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Weglot Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Weglot Plugin and the shortcodes it provides:

Plugin Icon
Weglot Translate – Translate your WordPress website and go multilingual

"Weglot Translate is a WordPress plugin that enables you to effortlessly convert your website into a multilingual platform. With Weglot, reaching a global audience has never been easier."

★★★★☆ (1571) Active Installs: 50000+ Tested with: 6.3.2 PHP Version: 7.0
Included Shortcodes:
  • [weglot_switcher]

Weglot [weglot_switcher] Shortcode

The Weglot Switcher shortcode is a functional piece of code that displays a language switcher on your website. It calls back to the Weglot Switcher function, returning an HTML button for language selection.

Shortcode: [weglot_switcher]

Examples and Usage

Basic example – The Weglot switcher shortcode is used to display the language switcher on your WordPress site. This basic example shows how to use the shortcode without any parameters.

[weglot_switcher /]

Advanced examples

The Weglot switcher shortcode also accepts various parameters to customize the language switcher’s appearance. The following examples show how to use these parameters.

1. Displaying the language switcher with a specific language. This example shows how to display the language switcher with English (‘en’) as the default language.

[weglot_switcher lang="en" /]

2. Changing the language switcher’s type. This example shows how to display the language switcher as a dropdown list instead of the default button type.

[weglot_switcher type="dropdown" /]

3. Customizing the language switcher’s style. This example shows how to display the language switcher with a custom CSS class.

[weglot_switcher class="my-custom-class" /]

4. Combining multiple parameters. This example shows how to display the language switcher with English as the default language, as a dropdown list, and with a custom CSS class.

[weglot_switcher lang="en" type="dropdown" class="my-custom-class" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [weglot_switcher] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'weglot_switcher', array( $this, 'weglot_switcher_callback' ) );

Shortcode PHP function:

function weglot_switcher_callback() {
		return $this->button_services->get_html( 'weglot-shortcode' ); //phpcs:ignore
	}

Code file location:

weglot/weglot/src/actions/front/class-shortcode-weglot.php

Conclusion

Now that you’ve learned how to embed the Weglot Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *