• Resolved vshura

    (@vshura)


    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; 
        } 
    }
    ?>
    
    • This topic was modified 5 years, 3 months ago by vshura.
    • This topic was modified 5 years, 3 months ago by vshura.
    • This topic was modified 5 years, 3 months ago by vshura.
    • This topic was modified 5 years, 3 months ago by vshura.
Viewing 1 replies (of 1 total)
  • Plugin Author Pothi Kalimuthu

    (@pothi)

    Hello @vshura,

    Thanks for your time to create shortcodes with all relevant links and documentation. The aim of this plugin is to fix the shortcoming with the built-in WordPress function wp_is_mobile. So, when WP core fixes wp_is_mobile in the future, this plugin would be retired. At that time, I don’t want anyone to miss any other features that this plugin may have. That’s one of the reasons no other feature was added to the plugin. I actually encourage add-on plugins or standalone plugins, if any other feature is missing in this plugin.

    Just updated the FAQ section of this plugin, mentioning the above point, as feature requests are coming bit frequently.

    Pothi.

Viewing 1 replies (of 1 total)
  • The topic ‘Info – how to create Shortcodes’ is closed to new replies.