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 want a little help loading a custom stylesheet in wordpress. I'm using PHP to check if the user agent is BlackBerry. If yes, I want to load blackberry.css, if no, regular wordpress style.css.

Here's what I have so far:

$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
   $pos_blackberry = strrpos($ua, "blackberry");
   $pos_webkit = strrpos($ua, "webkit");

   if (!($pos_blackberry === false)) {
      if (!($pos_webkit === false)) {

         **//load blackberry.css**

   } else {
     wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri() );

Question: what is the "grammatically correct" WordPress syntax for loading blackberry.css stylesheet?

share|improve this question
up vote 2 down vote accepted

Well... You've already used wp_enqueue_style. Use it again. That is the canonical mechanism for loading stylesheets either by itself or in combination with wp_register_style


I feel compelled to note that user agent sniffing is not especially reliable. Is it not possible to do this with media queries?



share|improve this answer
Thank you very much for your help, @s_ha_dum. How would you target a notoriously CSS-resistant BlackBerry with a media query? I'd appreciate your further advice! – Astoria May 14 '13 at 15:08
Pure CSS question are off-topic per the faq. Try Stack Overflow. – s_ha_dum May 14 '13 at 15:13
Well, @s_ha_dum, I wasn't asking a full-fledged question, but rather a further clarification of your reply to a question that was perfectly wordpress-related. Obviously, you know how to target BlackBerry devices with media queries, otherwise you wouldn't mention that method in your initial response in the first place. So why make it such a secret? Explaining it would only enrich your answer. – Astoria May 14 '13 at 15:19
Actually, I asked if there was a reason you can't do it with media queries. I wasn't claiming any particular expertise. Sorry for the confusion. Blackberry is such a tiny percent of the traffic I see (making up 0.13% of our traffic according to Google Analytics) I have never gone out of my way to tweak for it. I see more IE6 than that and I don't go out of my way for it either. But ... responsive.co.za/blackberry-specific-media-queries and stackoverflow.com/questions/6404617/blackberry-media-query should get you going. – s_ha_dum May 14 '13 at 15:28

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.