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?


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?



  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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