WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for a way to conditionally load different scripts if the user is accessing the admin area from a mobile device.

In my case I'm looking to restrict the user to just be able to make new posts, so if you log in to the admin area from a mobile device you're redirected to the post listing and the admin menu isn't even available.


share|improve this question
So far the admin UI isn't accessible on a smart phone anyway. Why then bother? – kaiser Nov 12 '12 at 10:47
up vote 2 down vote accepted

wp_is_mobile should be the switch you need, but you may be talking about a lot of edits to a lot of components to do what you describe. I don't know enough about the rest of your code to guess at what kinds of things you would need.

share|improve this answer
Thanks for your reply! That could've been a valid approach. Unfortunately I'm on 3.3.2 and cannot upgrade WP because the site is built with very many custom scripts that possibly would break if WP is upgraded. – INT Nov 11 '12 at 23:53
You should be able to copy the function and use it anyway. It doesn't do anything but check the $_SERVER['HTTP_USER_AGENT']. – s_ha_dum Nov 11 '12 at 23:56

While s_ha_dum's answer is not only not wrong, but exactly the answer you'd expect to get, I'd highly advise against using it, whether you are on 3.4+ or not.

User agent sniffing sucks. Whether done manually or via a core function. Period.

For one, new UA strings pop up like wildfire. For another, a good number of browsers pretend to be something else anyway.

For another: What is a mobile device?
Old phones only?
All smart phones?
Does that include tablets?

You see, it is impossible to identify a mobile device and categorize it into either being one or not. The only reliable way of serving conditional content is via screen- or viewport-width, respectively. Pixel-density is another factor to consider, but ought not to apply to your issue.

To stray from negativity and provide something somewhat useful: Hence, I'd suggest hiding admin menu items via css mediaqueries and/or js.

share|improve this answer
Media queries are useful, though not without problems, but won't help "conditionally load different scripts" as in the opening question. Javascript might help with that but won't help with anything you might want to do server-side-- for example, reduce the resources sent over a mobile connection. For that you have few choices and none of them are very good, including UA sniffing, though, if my smart phone browser lies about being a desktop, which it does, I'd rather have that respected than not. – s_ha_dum Nov 12 '12 at 1:10
@s_ha_dum Media Queries can't lie about being a desktop/tablet/mobile/etc. They tell you about the width of a viewport. Period. – kaiser Nov 12 '12 at 10:46
@kaiser, I understand that, but my browser can lie about the user agent, and it does, and it does because I purposefully told it to do so. – s_ha_dum Nov 12 '12 at 14:10
@s_ha_dum I didn't mean to discredit you at all. I phrased my answer in a response to yours, that might appear to be not very nice, but it pertains to the nature of the issue at hand only. Your answer is 100% correct and does totally apply to the situation. In fact, I just upvoted it, for it is a quality answer. It simply is a technique which I do not like at all. At this point we're about to leave rational argument and are scratching the realm of opinion. And that's okay. Ideally, every question on every stack ought to have two valid answers showing different approaches, no?! – Johannes Pille Nov 13 '12 at 1:04
@JohannesPille, no worries. I took no offense. :) – s_ha_dum Nov 13 '12 at 4:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.