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

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

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

Tested with WordPress v. 4.8
Last Modified: 15.05.2018
Last Reviewed: 15.05.2018

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

3.9 (77.5%) 8 votes

Please report broken snippets.

Report Broken Snippet