Checking Specific Devices In WordPress

We all know that, there are many specific devices built day by day and also used to browse any of your site. Also, day by day, the number of the web browsers is increasing. But, are they built with the same format, ie, globally? Well, the answer to this would be no. All of the developed browsers are built differently with each other, which makes the web developer and designer hard to work on compatibility. But, if you are WordPress developer, then, you are in luck, WordPress has built in functionality for checking specific devices from which the visitor to your site is visiting.

Nowadays, as we had already told earlier, there are many browsers used throughout by the user to surf the internet. And the bitter truth about it is, all of them will be rendering the sites in same way, if no any specific functionality is added. So, what if we want to control the display of the site specific to the specific browser, ie, different styling for the different browser, as well as controlling the functionality too.

For eg:- what if you want to remove some images from displaying in the Mozilla Firefox browser only. Is is possible? Well, if you are using WordPress, then, it is possible as it has the custom function to check for the specific devices used by the visitor to visit your site. So, here we will provide the code provided by WordPress, which is global variable to check for the specific devices used by the user. The code for this is provided below:

global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
if ($is_lynx) {
echo "You are using Lynx";
} elseif ($is_gecko) {
echo "You are using Firefox";
} elseif ($is_IE) {
echo "You are using Internet Explorer";
} elseif ($is_opera) {
echo "You are using Opera";
} elseif ($is_NS4) {
echo "You are using Netscape";
} elseif ($is_safari) {
echo "You are using Safari";
} elseif ($is_chrome) {
echo "You are using Chrome";
} elseif ($is_iphone) {
echo "You are using an iPhone";

Here, in the above code, you can see that the WordPress has setup different global variables for the different browsers used. So, from the above code, we can see that, if you are using the Chrome Browser, then, the output will be as You are using Chrome, and for Firefox, it will be You are using Firefox and so on. So, from this global variable used in our theme or plugin, we can easily separate different functionality of the developed theme or plugin differently for the specific devices used by the users.

Now, after you have read our above post and tried it in your local development environment and was successful, then, we can assume that now you are familiar on checking for the specific devices used by the visitors to your site with the help of the WordPress built in function.

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.