<?php // [desktoponly] shortcode add_shortcode('desktoponly', 'wp_snippet_desktop_only_shortcode'); function wp_snippet_desktop_only_shortcode($atts, $content = null){ if( !wp_is_mobile() ){ return wpautop( do_shortcode( $content ) ); } else { return null; } } // [mobileonly] shortcode add_shortcode('mobileonly', 'wp_snippet_mobile_only_shortcode'); function wp_snippet_mobile_only_shortcode($atts, $content = null){ if( wp_is_mobile() ){ return wpautop( do_shortcode( $content ) ); } else { return null; } } ?>

Now, we can wrap any text that should only be visible in the mobile browser with the shortcode [mobileonly][/mobileonly].

Example: 

[mobileonly] This is a mobile only text. [/mobileonly]

Similar patterns apply to the desktop-only version as well.

Example:

[desktoponly] This is a desktop only text. [/desktoponly]

Video: Showing WordPress Mobile Only Content Using Plugin

If you liked this post, please consider sharing it with your friends:


Source link

Leave a Reply

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