Here is how to detect if user has opened site in mobile device or desktop. For this we're using JavaScript code which will be executed at client-side.
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
  $("body").addClass("mobile");
}
else {
  $("body").addClass("desktop");
}

Reference:

Submitted by ychaugule on