{"id":297,"date":"2019-08-27T05:38:22","date_gmt":"2019-08-27T05:38:22","guid":{"rendered":"http:\/\/shaplakanon.com\/wpsupport\/?p=297"},"modified":"2019-08-27T05:38:24","modified_gmt":"2019-08-27T05:38:24","slug":"how-to-detect-mobile-user-in-wordpress","status":"publish","type":"post","link":"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/","title":{"rendered":"How to detect mobile user in wordpress?"},"content":{"rendered":"\n

WordPress has a cool function to detect if user visiting your site from mobile or desktop.<\/p>\n\n\n\n

wp_is_mobile<\/strong><\/h4>\n\n\n\n

This Conditional Tag checks if the user is visiting using a mobile device. This is a boolean function, meaning it returns either TRUE or FALSE. It works through the detection of the browser user agent string ($_SERVER[‘HTTP_USER_AGENT’])<\/p>\n\n\n\n

Do not think of this function as a way of detecting phones. Its purpose is not detecting screen width, but rather adjusting for the potentially limited resources of mobile devices. A mobile device may have less CPU power, memory and\/or bandwidth available. This function will return true for a tablet, as it too is considered a mobile device. It is not<\/strong> a substitute for CSS media queries or styling per platform.<\/p>\n\n\n\n

One way that this function could be used in a theme is to produce a very light version of the site that does not have the large payload of the desktop site. Note that both the desktop and the mobile versions of the page will still need to be responsive, as an older portrait phone will have a significantly different width than a modern iPad in landscape. wp_is_mobile() will be true for both. Similarly a desktop browser window may not be displayed at full width. Essentially this approach may double the amount of work you will need to put into the theme. Yet for a tightly optimized theme or a unique mobile experience, it may be essential. It also means that a proper theme may have at least three different responsive design specs: Desktop, Mobile and AMP.<\/p>\n\n\n\n

Additionally, care must be taken when using this function in a public theme. If your theme works differently for mobile devices and desktop devices, any page caching solution used MUST keep separate mobile\/non-mobile buckets. Many caching solutions do not do this or charge for this feature. Even the most detailed read me file may not be able to adequately explain these details.<\/p>\n\n\n\n

How to use?<\/strong><\/h4>\n\n\n\n
<?php\nif ( wp_is_mobile() ) {\n \/* Include\/display resources targeted to phones\/tablets here *\/\n} else {\n \/* Include\/display resources targeted to laptops\/desktops here *\/\n}\n?><\/pre>\n\n\n\n
Is there any wordpress plugin for mobile detection?<\/strong><\/pre>\n\n\n\n

yes, there is a mobile detect plugin available in wordpress plugin directory.<\/p>\n\n\n\n

what is mobile detect plugin?<\/strong><\/h4>\n\n\n\n

Conditional Display for Mobile is a mobile detect plugin that can be used to control what content is displayed depending on the visitor\u2019s device or web browser. For example, you might want to display some content only on iPhone and iPad, or you want to hide the content on mobile and tablet devices. The plugin also supports add start time and end time to shedule the content so it will only be displayed in the specified date and time. <\/p>\n\n\n\n

Features<\/strong><\/p>\n\n\n\n

  • Include or exclude devices<\/li>
  • Detect iPhone, iPad, iPod, Android, Mobile, Windows, Linux and Mac<\/li>
  • Include or exclude web browsers<\/li>
  • Detect Mozilla Firefox, Google Chrome, Safari, Opera, Internet Explorer 6\/7\/8\/9\/10\/11 and Microsoft Edge<\/li>
  • Add start time and end time to schedule the content so it will only be displayed in the specified date and time<\/li>
  • Support shortcode in the content<\/li>
  • Use the conditional display shortcode in text widget<\/li>
  • PHP functions to detect mobile and browser<\/li><\/ul>\n\n\n\n

    If you need help with plugin or anything with wordpress, feel free to contact us.<\/p>\n","protected":false},"excerpt":{"rendered":"

    WordPress has a cool function to detect if user visiting your site from mobile or desktop. wp_is_mobile This Conditional Tag<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[80,81,82],"class_list":["post-297","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-mobile-browser","tag-mobile-detection","tag-mobile-plugin"],"yoast_head":"\nHow to detect mobile user in wordpress? - WordPress Support<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to detect mobile user in wordpress? - WordPress Support\" \/>\n<meta property=\"og:description\" content=\"WordPress has a cool function to detect if user visiting your site from mobile or desktop. wp_is_mobile This Conditional Tag\" \/>\n<meta property=\"og:url\" content=\"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/\" \/>\n<meta property=\"og:site_name\" content=\"WordPress Support\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/facebook.com\/getwpsupport\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-27T05:38:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-08-27T05:38:24+00:00\" \/>\n<meta name=\"author\" content=\"Ruhul Amin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ruhul24\" \/>\n<meta name=\"twitter:site\" content=\"@ruhul24\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ruhul Amin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/\"},\"author\":{\"name\":\"Ruhul Amin\",\"@id\":\"https:\/\/shaplakanon.com\/wpsupport\/#\/schema\/person\/f5f224239283c27426dadc2e4cc9a825\"},\"headline\":\"How to detect mobile user in wordpress?\",\"datePublished\":\"2019-08-27T05:38:22+00:00\",\"dateModified\":\"2019-08-27T05:38:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/\"},\"wordCount\":531,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/shaplakanon.com\/wpsupport\/#organization\"},\"keywords\":[\"mobile browser\",\"mobile detection\",\"mobile plugin\"],\"articleSection\":[\"wordpress\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/\",\"url\":\"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/\",\"name\":\"How to detect mobile user in wordpress? - WordPress Support\",\"isPartOf\":{\"@id\":\"https:\/\/shaplakanon.com\/wpsupport\/#website\"},\"datePublished\":\"2019-08-27T05:38:22+00:00\",\"dateModified\":\"2019-08-27T05:38:24+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/shaplakanon.com\/wpsupport\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to detect mobile user in wordpress?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/shaplakanon.com\/wpsupport\/#website\",\"url\":\"https:\/\/shaplakanon.com\/wpsupport\/\",\"name\":\"WordPress Support\",\"description\":\"Wordpress Repair, migration, speed optimization\",\"publisher\":{\"@id\":\"https:\/\/shaplakanon.com\/wpsupport\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/shaplakanon.com\/wpsupport\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/shaplakanon.com\/wpsupport\/#organization\",\"name\":\"WordPress Support\",\"url\":\"https:\/\/shaplakanon.com\/wpsupport\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/shaplakanon.com\/wpsupport\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/shaplakanon.com\/wpsupport\/wp-content\/uploads\/sites\/2\/2022\/05\/cropped-logo-9674824.png\",\"contentUrl\":\"https:\/\/shaplakanon.com\/wpsupport\/wp-content\/uploads\/sites\/2\/2022\/05\/cropped-logo-9674824.png\",\"width\":274,\"height\":55,\"caption\":\"WordPress Support\"},\"image\":{\"@id\":\"https:\/\/shaplakanon.com\/wpsupport\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/facebook.com\/getwpsupport\/\",\"https:\/\/x.com\/ruhul24\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/shaplakanon.com\/wpsupport\/#\/schema\/person\/f5f224239283c27426dadc2e4cc9a825\",\"name\":\"Ruhul Amin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/shaplakanon.com\/wpsupport\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/28178d347289d520b52ece250f7042df?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/28178d347289d520b52ece250f7042df?s=96&d=mm&r=g\",\"caption\":\"Ruhul Amin\"},\"sameAs\":[\"https:\/\/shaplakanon.com\/wdc\/\"],\"url\":\"https:\/\/shaplakanon.com\/wpsupport\/author\/sabahat\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to detect mobile user in wordpress? - WordPress Support","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/","og_locale":"en_US","og_type":"article","og_title":"How to detect mobile user in wordpress? - WordPress Support","og_description":"WordPress has a cool function to detect if user visiting your site from mobile or desktop. wp_is_mobile This Conditional Tag","og_url":"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/","og_site_name":"WordPress Support","article_publisher":"https:\/\/facebook.com\/getwpsupport\/","article_published_time":"2019-08-27T05:38:22+00:00","article_modified_time":"2019-08-27T05:38:24+00:00","author":"Ruhul Amin","twitter_card":"summary_large_image","twitter_creator":"@ruhul24","twitter_site":"@ruhul24","twitter_misc":{"Written by":"Ruhul Amin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/#article","isPartOf":{"@id":"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/"},"author":{"name":"Ruhul Amin","@id":"https:\/\/shaplakanon.com\/wpsupport\/#\/schema\/person\/f5f224239283c27426dadc2e4cc9a825"},"headline":"How to detect mobile user in wordpress?","datePublished":"2019-08-27T05:38:22+00:00","dateModified":"2019-08-27T05:38:24+00:00","mainEntityOfPage":{"@id":"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/"},"wordCount":531,"commentCount":0,"publisher":{"@id":"https:\/\/shaplakanon.com\/wpsupport\/#organization"},"keywords":["mobile browser","mobile detection","mobile plugin"],"articleSection":["wordpress"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/","url":"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/","name":"How to detect mobile user in wordpress? - WordPress Support","isPartOf":{"@id":"https:\/\/shaplakanon.com\/wpsupport\/#website"},"datePublished":"2019-08-27T05:38:22+00:00","dateModified":"2019-08-27T05:38:24+00:00","breadcrumb":{"@id":"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/shaplakanon.com\/wpsupport\/how-to-detect-mobile-user-in-wordpress\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/shaplakanon.com\/wpsupport\/"},{"@type":"ListItem","position":2,"name":"How to detect mobile user in wordpress?"}]},{"@type":"WebSite","@id":"https:\/\/shaplakanon.com\/wpsupport\/#website","url":"https:\/\/shaplakanon.com\/wpsupport\/","name":"WordPress Support","description":"Wordpress Repair, migration, speed optimization","publisher":{"@id":"https:\/\/shaplakanon.com\/wpsupport\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/shaplakanon.com\/wpsupport\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/shaplakanon.com\/wpsupport\/#organization","name":"WordPress Support","url":"https:\/\/shaplakanon.com\/wpsupport\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/shaplakanon.com\/wpsupport\/#\/schema\/logo\/image\/","url":"https:\/\/shaplakanon.com\/wpsupport\/wp-content\/uploads\/sites\/2\/2022\/05\/cropped-logo-9674824.png","contentUrl":"https:\/\/shaplakanon.com\/wpsupport\/wp-content\/uploads\/sites\/2\/2022\/05\/cropped-logo-9674824.png","width":274,"height":55,"caption":"WordPress Support"},"image":{"@id":"https:\/\/shaplakanon.com\/wpsupport\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/facebook.com\/getwpsupport\/","https:\/\/x.com\/ruhul24"]},{"@type":"Person","@id":"https:\/\/shaplakanon.com\/wpsupport\/#\/schema\/person\/f5f224239283c27426dadc2e4cc9a825","name":"Ruhul Amin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/shaplakanon.com\/wpsupport\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/28178d347289d520b52ece250f7042df?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/28178d347289d520b52ece250f7042df?s=96&d=mm&r=g","caption":"Ruhul Amin"},"sameAs":["https:\/\/shaplakanon.com\/wdc\/"],"url":"https:\/\/shaplakanon.com\/wpsupport\/author\/sabahat\/"}]}},"_links":{"self":[{"href":"https:\/\/shaplakanon.com\/wpsupport\/wp-json\/wp\/v2\/posts\/297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shaplakanon.com\/wpsupport\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shaplakanon.com\/wpsupport\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shaplakanon.com\/wpsupport\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shaplakanon.com\/wpsupport\/wp-json\/wp\/v2\/comments?post=297"}],"version-history":[{"count":0,"href":"https:\/\/shaplakanon.com\/wpsupport\/wp-json\/wp\/v2\/posts\/297\/revisions"}],"wp:attachment":[{"href":"https:\/\/shaplakanon.com\/wpsupport\/wp-json\/wp\/v2\/media?parent=297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shaplakanon.com\/wpsupport\/wp-json\/wp\/v2\/categories?post=297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shaplakanon.com\/wpsupport\/wp-json\/wp\/v2\/tags?post=297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}