Info – how to create Shortcodes
-
Not being an expert, I struggled with this plugin initially when trying to define mobile and non-mobile only content. However, method two on this page was of great help to make shortcodes
https://wp-snippet.com/snippets/display-content-mobile-desktop-using-wordpress-wp_is_mobile/
I’ve included the relevant parts of this page below in case the URL changes.
And then this plugin is great, because before I found this there was no easy way to distinguish between mobile phones and tablets. Good work!
==
Relevant material from above link:
Method 2 instructions
This snippet will allow you to use shortcodes[desktoponly] desktop content [/desktoponly]
or
[mobileonly] mobile content [/mobileonly]
to determine what content should be returned to the visitor.
Add this code to your functions.php
<?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; } } ?>
- The topic ‘Info – how to create Shortcodes’ is closed to new replies.