Multi Device Switcher Shortcode

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

Before starting, here is an overview of the Multi Device Switcher Plugin and the shortcodes it provides:

Plugin Icon
Multi Device Switcher

"Multi Device Switcher is a versatile WordPress plugin designed to effortlessly switch themes according to the device accessing your website, enhancing user experience."

★★★★✩ (11) Active Installs: 20000+ Tested with: 6.2.0 PHP Version: 5.6
Included Shortcodes:
  • [multi]

Multi Device Switcher [multi] Shortcode

The Multi-Device-Switcher shortcode is a powerful tool for managing content display across various devices. This shortcode, when used, checks the type of device accessing the website. If the device matches the ‘device’ attribute specified within the shortcode or if the device is a PC, the enclosed content is displayed. If not, it returns an empty string, hiding the content.

Shortcode: [multi]

Parameters

Here is a list of all possible multi shortcode parameters and attributes:

  • device – specifies the type of device for content visibility

Examples and Usage

Basic example – The basic usage of the multi-device-switcher plugin shortcode can be done by specifying the device parameter in the shortcode. The device parameter is used to determine the type of device the content will be displayed on.

[multi device="mobile"]

Advanced examples

It is possible to use the shortcode in a more advanced way by including additional parameters. For instance, you can specify more than one device in the shortcode. This will display the content on all specified devices. Remember, the device names should be separated by a comma.

[multi device="mobile,tablet"]

Additionally, you can use the shortcode to display different content for different devices. To do this, you will need to use the shortcode multiple times with different device parameters and different content.

[multi device="mobile"]Mobile content here[/multi]
[multi device="tablet"]Tablet content here[/multi]

These advanced usage examples provide flexibility in managing the display of content across different devices.

PHP Function Code

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

Shortcode line:

add_shortcode( 'multi', array( $this, 'shortcode_display_switcher' ) );

Shortcode PHP function:

function shortcode_display_switcher( $atts, $content = '' ) {
		$atts = shortcode_atts(
			array(
				'device' => '',
			),
			$atts
		);

		if ( empty( $atts['device'] ) && ( $this->is_multi_device( $atts['device'] ) || $this->is_pc_switcher() ) ) {
			return $content;
		}
		elseif ( ! empty( $atts['device'] ) && $this->is_multi_device( $atts['device'] ) && ! $this->is_pc_switcher() ) {
			return $content;
		}

		return '';
	}

Code file location:

multi-device-switcher/multi-device-switcher/multi-device-switcher.php

Conclusion

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