Sometimes, browsers just don't behave. While working on a WordPress site, I had a particular styling issue that was affecting Safari. I was wondering what the best way to target the browser was.
If you didn't know, there are some primitive browser detection booleans that are built into WordPress.
Using those primitives, I was able to whip up a little snippet that adds classes to the body tag depending on the browser - no plugins required.
As you can see, we simply loop over each one of those browser booleans and append them to the output.
Easy, and no plugin needed. Just add that code to your functions.php
file.
James Doyle
I'm a full-stack developer, co-organizer of PHP Vancouver meetup, and winner of a Canadian Developer 30 under 30 award. I'm a huge Open Source advocate and contributor to a lot of projects in my community. When I am not sitting at a computer, I'm trying to perfect some other skill.