Why Hard Working Classes Slack in WordPress

Nathan Ford wrote a great article about how you can use the attribute selector to define styles for a multitude of classes that share a common element. Initially I thought this was great (I actually still think this is a great idea), and used it in _s and Twenty Thirteen to simplify the clearfix selector and some others. We used [class*="site"] and [class*="content"], to grab all classes that contained those two words, essentially addressing our entire page structure with two selectors. Awesome, right?

Well, it turns out there are a few issues with this approach. After a while we received a report that Modernizr uses a generatedcontent class on the html element, screwing with the rest of the site because the styles for the [class*="content"] selector were applied. We also received reports from WordPress.com, where users specified tags, categories, or post titles that contained one of our two words. Since WordPress adds all categories and tags as classes in post_class(), this, again, broke the site’s layout.

I still think this a valid approach in projects where you can control the class namespace. Since you can’t really do that in WordPress, it’s not a good approach for theme developers.

Attachment Body Classes

There was an interesting bug reported for Twenty Twelve recently: The .single-attachment body class only gets applied when the attachment’s parent is a post (or custom post type). If the attachment’s parent happens to be a page, that class is missing.

In case you have been using .single-attachment to specify styles for the image attachment page, make sure to test your theme with images that have a page as a parent. And use the .attachment body class in the future. ;)