Wonder Conditional Display Shortcode

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

Before starting, here is an overview of the Wonder Conditional Display Plugin and the shortcodes it provides:

Plugin Icon
Conditional Display for Mobile – Mobile Detect Plugin

"Conditional Display for Mobile – Mobile Detect Plugin is a smart tool for WordPress. It enables content visibility based on the user's device, enhancing user experience with device-specific display."

★★★★★ (7) Active Installs: 3000+ Tested with: 5.9.8 PHP Version: false
Included Shortcodes:
  • [wonderplugin_cond]

Wonder Conditional Display [wonderplugin_cond] Shortcode

The Wonderplugin-Conditional-Display shortcode enables content visibility based on device type, browser, and specific time frames. It checks if the device or browser is included or excluded in the attributes. If included, content is displayed; if excluded, it’s hidden. The shortcode also handles time conditions, displaying content only within the specified start and end times.

Shortcode: [wonderplugin_cond]

Parameters

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

  • deviceinclude – List of devices where content is displayed
  • deviceexclude – List of devices where content is not displayed
  • browserinclude – List of browsers where content is displayed
  • browserexclude – List of browsers where content is not displayed
  • starttime – Date and time when content starts to display
  • endtime – Date and time when content stops to display

Examples and Usage

Basic example – An example of using the ‘wonderplugin_cond’ shortcode to include content for a specific device (e.g., ‘mobile’).

[wonderplugin_cond deviceinclude="mobile"]Your content here[/wonderplugin_cond]

Advanced examples

Utilizing the shortcode to exclude content from a specific browser (e.g., ‘firefox’).

[wonderplugin_cond browserexclude="firefox"]Your content here[/wonderplugin_cond]

Using the shortcode to display content within a specific time frame. The ‘starttime’ and ‘endtime’ parameters are set in the ‘Y-m-d H:i:s’ format.

[wonderplugin_cond starttime="2022-03-01 00:00:00" endtime="2022-03-31 23:59:59"]Your content here[/wonderplugin_cond]

Combining multiple parameters for complex conditions. This example includes content for mobile devices, excludes it from the Firefox browser, and sets a specific display time frame.

[wonderplugin_cond deviceinclude="mobile" browserexclude="firefox" starttime="2022-03-01 00:00:00" endtime="2022-03-31 23:59:59"]Your content here[/wonderplugin_cond]

PHP Function Code

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

Shortcode line:

add_shortcode( 'wonderplugin_cond', array($this, 'shortcode_handler') );

Shortcode PHP function:

                    function shortcode_handler($atts, $content = null) {
		
		$show = true;
		
		// device include
		if ( isset($atts['deviceinclude']) )
		{
			$show = false;
			
			$deviceinclude = explode(',', strtolower($atts['deviceinclude']));
			foreach($deviceinclude as $device)
			{
				if ($this->check_device($device))
				{
					$show = true;
					break;
				}
			}
			
			if (!$show)
				return;
		}
		
		// device exclude
		if ( isset($atts['deviceexclude']) )
		{				
			$deviceexclude = explode(',', strtolower($atts['deviceexclude']));
			foreach($deviceexclude as $device)
			{
				if ($this->check_device($device))
				{
					$show = false;
					break;
				}
			}
				
			if (!$show)
				return;
		}
		
		// browser include
		if ( isset($atts['browserinclude']) )
		{
			$show = false;
				
			$browserinclude = explode(',', strtolower($atts['browserinclude']));
			foreach($browserinclude as $browser)
			{
				if ($this->check_browser($browser))
				{
					$show = true;
					break;
				}
			}
				
			if (!$show)
				return;
		}
		
		// browser exclude
		if ( isset($atts['browserexclude']) )
		{
			$browserexclude = explode(',', strtolower($atts['browserexclude']));
			foreach($browserexclude as $browser)
			{
				if ($this->check_browser($browser))
				{
					$show = false;
					break;
				}
			}
		
			if (!$show)
				return;
		}
			
		if ( isset($atts['starttime']) )
		{
			if ( current_time( 'timestamp' ) < strtotime( $atts['starttime'] ) )	
				$show = false;	
			
			if (!$show)
				return;
		}

		if ( isset($atts['endtime']) )
		{
			if ( current_time( 'timestamp' ) > strtotime( $atts['endtime'] ) )	
				$show = false;	

			if (!$show)
				return;
		}

		if ($show)
			return do_shortcode($content);
		
	}
                    

Code file location:

wonderplugin-conditional-display/wonderplugin-conditional-display/wonderplugin-cond.php

Conclusion

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