Checking Devices Used For Site View In WordPress

Nowadays, more are more websites are being built in as well as devices are too being built to browse your site from. But, what if you want to check that the visitor to your site is visiting via the mobile or desktops devices? Well, for this, if you are using WordPress for your site, then, it seems that you are in luck. WordPress has built in function to check that if the visitor to your site is visiting via the mobile devices or through the desktop devices, ie, the devices used to view your site.

From the above description, we came to know that the users to your website, will be viewing your sites by using any of the devices, either be it mobile or desktops. So, what if you want to control or enable the user to your site, to view the certain things in the certain devices only. Since, WordPress has built in function for this, hence, here we will provide the code to check for the devices used by the user when viewing the site. Here, what we will be providing is the built in function of WordPress to know that the devices being used to visit the site, is mobile device or not. The function provided by WordPress in order to check the mobile devices being used is provided below:

* Checking that the mobile devices is being used or not.
if ( wp_is_mobile() ) {
echo 'this is being used by the mobile device';
} else {
echo 'this is not being used by the mobile device.';

Here, in the above function wp_is_mobile(), is the WordPress function to check that the devices used by the user is a mobile device or not. So, if you want to control the display as well as other things for the desktop and mobile devices differently, then, you can utilize the above function and modify it according to the feature wanted by you for your site. For eg: if you want to add some CSS code only for the mobile devices, then, you can make use of the above code. Also, for the another example, if you want to display the slider only in the desktop browser only, then, you too, can make the utilize of this built in WordPress function for your site.

If you have followed the above example properly, then, we can assume that you are now familiar on checking for the specific devices used, ie, mobile or desktops, by the visitor to your site and can make the customization work according to the devices used, that best suits your site visitors.

Post navigation

Bishal Napit

Bishal Napit is a WordPress theme developer from Tansen, Palpa, with a passion to learn more on WordPress.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.