OS detection to display different links on WordPress page

1.1k Views Asked by At

I would like for my WordPress post link to refer people to different pages depending on the OS that they are using. For example to download Mac version of software if they are browsing from MacOS.

I saw a tutorial on how to add user OS in function.php file, but i have no idea how to implement function on a specific WP page.

1

There are 1 best solutions below

2
On

Based on that tutorial you don't need to change page link. On same page you can do that. Like section/button for Mac/windows.

Here how you can do:

Step1: Add the code on your functions.php then you will see on your website under body tag have a specific class if you are form Mac then "osx" or if you are from windows then "windows"

Step2: add class on you Mac section called "osxsection" & for windows section "windowssection"

Step3: Now do the css like this:

// to view the section on Mac
.osx .osxsection {
display: block !important;
}
.osxsection {
display: none;
}

// to view the section on Windows
.windows .windowssection {
display: block !important;
}
.windowssection {
display: none;
}

you can present that CSS code some different way also.

Try that hope it will help you :)