No, it will fail. There are literally thousands of mobile clients, and not all send a usable User-Agent header. There are better ways to adjust the site to small screens (which is not necessary the same as mobile!).
Use client side detection and offer a link to switch the view; save that option in a cookie.
I think the common misconception is that mobile == small screen. The Nexus 10 has more pixels than my big desktop screen, while my old laptop running a desktop Ubuntu shows just a 1024×768 pixels. Surface RT comes with 1366×768 pixels, a mouse (trackpad), a keyboard and a touch interface. And some UAs are just not detectable.
Which one will get the layout “optimized for mobile”?
Related Posts:
- Is it ok to use a function to output the text domain name in a wordpress theme
- Issue with wp_get_attachment_image() and SVG file type
- How to override a function when isn’t at functions.php
- deregister scripts on certain page
- contactform7 remove tags with “wpcf7_autop false” from functions.php
- How to count number of functions attached to an action hook?
- Show modified time if post is actually modified
- ajax live search for post title
- Show Video in Excerpt
- Display Total Number of Social Shares
- Override parent theme function that is not hooked or in the functions.php file
- function to include is_home, is_archive, is_category, is_author etc in one function?
- How to remove canonical url in wordpress? add_filter( ‘wpseo_canonical’, ‘__return_false’ ); not Working for me
- Child theme – copied some files from parent to child website still uses parent files
- get_the_excerpt() not returning anything when post has no excerpt
- Using locate-template & shortcodes doesn’t appear to work
- Widgets Section not displaying in theme customizer
- add sidebar area to header of child theme
- Why isn’t is_page_template() adding a body class?
- Query children and parent title
- How to make unique add_filter to the_content of specific page template files – so each template gets its own addition
- Hide the Private prefix on one specific page
- Creating loop within functions.php
- Limit filter upgrader_post_install to a single plugin
- How to test for Super Admin
- Adding a class to tag list in a function
- creating shortcode to pull json array
- Pass Shortcode Attribute to footer Script
- echo get_post_meta()
- Replace menu links with # and add name to its li
- Variable if post is sticky in functions.php
- Retrieve tags data in post body
- Change template on the fly based on post parent selection
- Current path on page in functions.php
- How do you publish a draft on WordPress
- How can I recompile js file in dist folder?
- Show Primary Category first when I display post categories
- Create a new query in function.php to filter blog posts
- Remove the product category module block from the Woocommerce product page
- Setting youtube size in functions.php
- How to get correct URLs in network wide menu (Multisite)?
- wp_get_archives custom function broken since upgrading to WP 3.7.1
- Remove category from url
- ‘Attempt to modify property of non-object’ warning
- Conditional functions.php on page template
- Optimizing a WordPress site
- different style sheet for just one page template
- Problem with comments_number()
- Functions when woocommerce isn’t installed
- How to target post and pages and not all post types in admin?
- How to get correct value from checked()?
- Dequeue script to prevent javascript event conflict on wordpress child theme
- While loop with an exception after a count is reached
- Return child theme url
- Passing global variable from header.php to functions.php
- How is $current_page passed in woocommerce_account_orders function?
- Upgraded server now class My_Walker_Nav_Menu extends Walker_Nav_Menu not working
- Functions php shortcode for displaying main menu with no child items
- How to include any template using Shortcode fuction?
- display a div on ervery site but not frontpage?
- Do we need to change our child function.php to require/include child dir files when we add an over-riding file.php into the child theme
- Replace header image on all other pages but home – URL issue
- Child theme functions.php
- How to echo Widget Title in Custom Frontend-Template Box
- Redirect to post after publish or update a published post
- Page Template Won’t Load Correct CSS File
- Getting images from media library and get_the_date() not working
- WordPress show bad the php hour and date
- Using add_image_size in functions.php to get original uploaded file
- show all the posts thumbnails
- the_excerpt function not showing image
- How to display this meta data (an array) in form of a function (created with a custom write panel)?
- Use a filter for wp_robots to block CPT/feed/
- How do I change where “You must be logged in to comment” directs users?
- Login cookies blocked after customizing hashing method
- Order column custom date using pre_get_posts
- query_vars treat as single var from URL
- Running javascript without hooking wp_head
- Remove text after a dot and a colon in Woocommerce product title
- Enable CORS Request for hostname using IP address
- Change default color scheme in twentyfifteen child theme?
- Restrict access if logged out except for homepage
- Add meta data in head from theme
- what is `get_section()` and how to use it?
- DISABLE wordpress upgrade page
- How to echo the translated custom field?
- Only Show One Category Name Per Post
- Moving CDN jQuery to footer does not work?
- Pass max posts to Javascript
- Register a widget area when a theme option has been saved?
- Blank child theme – functions.php problem
- update_usermeta don’t work
- Hiding Google Analytics code based on theme options
- How do I make my child theme’s CSS update when I save it?
- Bulk set Post Title as Tag where Tag is Empty Function
- How to resize image from import image url?
- Vimeo video play button color function
- How to overwrite image if it already exists – WordPress, Gravity form
- Change TinyMCE undeline outpout
- Loading newest dependency javascript module file in functions.php