EN / ZH
WordPress Shortcode to Hide Content on Mobile Devices

These days, more and more people are building blogs and websites with WordPress, and many have optimized their sites for mobile devices. However, some content that works well for desktop readers may not be suitable for mobile readers. That’s why I’m sharing this method for hiding content on mobile devices using WordPress shortcodes.

The following shortcode makes published content invisible on mobile devices.

function not_mobile_shortcode($atts, $content = '') {
    if (wp_is_mobile() === true) {
        $content = '';
    }
    return $content;
}
add_shortcode('not_mobile', 'not_mobile_shortcode');

Add the code to your theme’s functions.php, then use the shortcode when writing posts:

[not_mobile]Hidden content[/not_mobile]

Content wrapped in these tags will be invisible when viewed on a mobile browser.