How to display content for mobile- or desktop only using WordPress “wp_is_mobile”.

Did you know that you can use WordPress built-in “mobile detect” function wp_is_mobile to create a simple shortcode that can hide certain parts of your content from mobile visitors and-/or desktop visitors.

The wp_is_mobile function returns true when your site is viewed from a mobile browser. Using this function you can create adaptive-/responsive wordpress themes based on visitor device. This snippet will allow you to use shotcodes the [desktoponly] desktop content [/desktoponly] or [mobileonly] mobile content [/mobileonly] to determine what content should be returned to the visitor.

Instructions
Add this code to your functions.php

Related links:
https://codex.wordpress.org/Function_Reference/wp_is_mobile

Snippet Info

Tested with Wordpress v. 4.7.3

How to display content for mobile- or desktop only using WordPress “wp_is_mobile”.
5 (100%) 3 votes
Please report broken snippets.
Report Broken Snippet