Multilanguage Shortcode

Below, you’ll find a detailed guide on how to add the Multilanguage 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 Multilanguage Plugin shortcode not to show or not to work correctly.

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

Plugin Icon
Multilanguage by BestWebSoft – WordPress Translation Plugin and Language Switcher

"Multilanguage by BestWebSoft is a comprehensive WordPress translation plugin and language switcher. It seamlessly translates and transitions your site's content into various languages, enhancing global accessibility."

★★★☆✩ (89) Active Installs: 5000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [multilanguage_switcher]

Multilanguage [multilanguage_switcher] Shortcode

The Multilanguage Switcher shortcode enables a language switcher on your WordPress site. It allows users to select their preferred language from a dropdown menu, enhancing site usability. The related PHP code creates a function that generates the language switcher. The switcher’s layout can vary, ranging from dropdown titles or icons to flag icons. The function also enables Google’s language switcher. The shortcode is useful for multilingual sites, increasing accessibility for international users.

Shortcode: [multilanguage_switcher]

Examples and Usage

Basic example – Displaying the language switcher using the default settings.

[multilanguage_switcher /]

Advanced examples

Displaying the language switcher with a custom layout. In this case, the layout is set to ‘drop-down-titles’, which means that the language switcher will be displayed as a drop-down list with language names as titles.

[multilanguage_switcher layout='drop-down-titles' /]

Displaying the language switcher with a custom layout and additional parameters. In this case, the layout is set to ‘flags-icons’, which means that the language switcher will be displayed as a list of flags. The ‘exclude’ parameter is used to exclude certain languages from the switcher. Here, the languages with the locales ‘en_US’ and ‘fr_FR’ are excluded.

[multilanguage_switcher layout='flags-icons' exclude='en_US,fr_FR' /]

Using the shortcode to display the language switcher as a Google Translate widget. The layout is set to ‘gt-vertical’, which means that the widget will be displayed in a vertical format. The ‘gaTrack’ parameter is used to enable Google Analytics tracking for the widget.

[multilanguage_switcher layout='gt-vertical' gaTrack='true' /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'multilanguage_switcher', 'mltlngg_get_switcher_block' );

Shortcode PHP function:

function mltlngg_get_switcher_block( $mltlngg_language_switcher = false ) {
		global $mltlngg_current_language, $mltlngg_get_default_language, $mltlngg_enabled_languages, $current_blog, $mltlngg_options, $wp_customize;

		if ( ! $mltlngg_language_switcher ) {
			$mltlngg_language_switcher = $mltlngg_options['language_switcher'];
		}

		if ( is_array( $mltlngg_language_switcher ) && isset( $mltlngg_language_switcher['layout'] ) ) {
			$mltlngg_language_switcher = $mltlngg_language_switcher['layout'];
		}

		$switcher = '';
		/* Language switcher style */
		switch ( $mltlngg_language_switcher ) {
			case 'drop-down-titles':
				$options = '';
				foreach ( $mltlngg_enabled_languages as $item ) {
					if ( $item['locale'] !== $mltlngg_current_language ) {
						$options .= '<li>
							<button class="mltlngg-lang-button-icons" name="mltlngg_change_display_lang" value="' . $item['locale'] . '" title="' . $item['name'] . '">'
								. $item['name'] .
							'</button>
						</li>';
					} else {
						$current_language_name = $item['name'];
					}
				}
				$switcher .=
					'<ul class="mltlngg-lang-switch mltlngg-lang-switch-names">
						<li>
							<a>' . $current_language_name . '</a>
							<ul>' . $options . '</ul>
						</li>
					</ul>';
				break;
			case 'drop-down-icons':
				$options = '';
				foreach ( $mltlngg_enabled_languages as $item ) {
					if ( $item['locale'] !== $mltlngg_current_language ) {
						$flag     = ( empty( $item['flag'] ) ) ? plugins_url( 'images/flags/', __FILE__ ) . $item['locale'] . '.png' : $item['flag'];
						$options .= '<li>
							<button class="mltlngg-lang-button-icons" name="mltlngg_change_display_lang" value="' . $item['locale'] . '" title="' . $item['name'] . '">
								<img class="mltlngg-lang" src="' . $flag . '" alt="' . $item['name'] . '">
							</button>
						</li>';
					} else {
						$current_language_flag = ( empty( $item['flag'] ) ) ? plugins_url( 'images/flags/', __FILE__ ) . $item['locale'] . '.png' : $item['flag'];
					}
				}
				$switcher .=
					'<ul class="mltlngg-lang-switch">
						<li>
							<img src="' . $current_language_flag . '">
							<ul>' . $options . '</ul>
						</li>
					</ul>';
				break;
			case 'flags-icons':
				foreach ( $mltlngg_enabled_languages as $item ) {
					$flag      = ( empty( $item['flag'] ) ) ? plugins_url( 'images/flags/', __FILE__ ) . $item['locale'] . '.png' : $item['flag'];
					$switcher .=
						'<button class="mltlngg-lang-button-icons" name="mltlngg_change_display_lang" value="' . $item['locale'] . '" title="' . $item['name'] . '">
							<img class="' . ( $item['locale'] === $mltlngg_current_language ? 'mltlngg-current-lang' : 'mltlngg-lang' ) . '" src="' . $flag . '" alt="' . $item['name'] . '">
						</button>';
				}
				break;
			case 'gt':
				$switcher .= '<div id="mltlngg_google_switcher"></div>';
				mltlngg_enqueue_google_script( 'dropdown' );
				break;
			case 'gt-horizontal':
				$switcher .= '<div id="mltlngg_google_switcher"></div>';
				mltlngg_enqueue_google_script( 'horizontal' );
				break;
			case 'gt-vertical':
				$switcher .= '<div id="mltlngg_google_switcher"></div>';
				mltlngg_enqueue_google_script( 'vertical' );
				break;
			case 'drop-down-list':
			default:
				$options = '';
				foreach ( $mltlngg_enabled_languages as $item ) {
					if ( $item['locale'] !== $mltlngg_current_language ) {
						$flag     = ( empty( $item['flag'] ) ) ? plugins_url( 'images/flags/', __FILE__ ) . $item['locale'] . '.png' : $item['flag'];
						$options .= '<li>
							<button class="mltlngg-lang-button-icons" name="mltlngg_change_display_lang" value="' . $item['locale'] . '" title="' . $item['name'] . '">
								<img class="mltlngg-lang" src="' . $flag . '" alt="' . $item['name'] . '"> ' . $item['name'] .
							'</button>
						</li>';
					} else {
						$current_language_name = $item['name'];
						$current_language_flag = ( empty( $item['flag'] ) ) ? plugins_url( 'images/flags/', __FILE__ ) . $item['locale'] . '.png' : $item['flag'];
					}
				}
				$switcher .=
					'<ul class="mltlngg-lang-switch mltlngg-lang-switch-names">
						<li>
							<a>
								<img src="' . $current_language_flag . '"> ' . $current_language_name .
							'</a>
							<ul>' . $options . '</ul>
						</li>
					</ul>';
				break;
		}

		if ( ! in_array( $mltlngg_language_switcher, array( 'gt', 'gt-horizontal', 'gt-vertical' ), true ) ) {
			$switcher = '<form class="mltlngg_switcher" name="mltlngg_change_language" method="post" action="">' . $switcher . '</form>';
		}

		return $switcher;
	}

Code file location:

multilanguage/multilanguage/multilanguage.php

Conclusion

Now that you’ve learned how to embed the Multilanguage 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 *