Display Content for Mobile Only with wp_is_mobile

There is a function called wp_is_mobile that provides a condition to display content only when the user is viewing on mobile. The function returns true when the site is loaded on mobile. Use it like this:

<?php  if( wp_is_mobile()){  ?>
// mobile stuff goes here
<?php } else { ?>
// desktop stuff goes here
<?php  } ?>

Note: Make sure your caching mechanism caches separately for mobile and desktop. You can do this for example with the WP-Rocket plugin.

Discussion
[  0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!