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 withwp_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?
Reference
http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri