WP_Styles class in WordPress allows for a few extra bits of fine-tuning via the
extra property, which is amended by calling
add_data( $handle, $key, $value ) method on the global
Persistent, Preferred and Alternate Style Sheets
Back at the end of 1999, the HTML4 spec defined persistent, preferred and alternate style sheets, and several of the browsers at the time implemented a user interface for users to access these as they wanted.
Several better concepts came along, such as sites doing on-site front-end or back-end style switchers, which solved some of the issues such as persistence on page reloads, supporting browsers which didn’t yet support a user interface, and avoiding downloading multiple style sheets that a user may never actually select.
Persistent style sheets are always loaded by the browser, and the
link element does not have a
title attribute. The Preferred (default) alternate style sheet has a
title attribute, and the other alternate style sheets also have
alternate as one of the
rel attribute values.
However, the technique is still valid today, and can be implemented when enqueueing style sheets in WordPress. Here’s how you might add a couple of alternative style sheets (with one marked as the default alternative, or preferred) for instance:
|1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30||
On Firefox for instance, a user can pick between these style sheets via the View -> Page Styles menu item:
Internet Explorer Style Sheets
Another extra is the ability to set a conditional comment, as used for adding IE-specific style sheets. Previously it had to be done by enqueueing the style sheet for all browsers, and then filtering the
style_loader_tag for that handle and adding the conditional comments in around it. Now we can just do:
|1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16||
This has the advantage of being significantly less code, and the actual condition could come from a variable or be filterable.
WordPress also appears to support other extras, such as
rtl which would allow you to mark an enqueued style sheet as only being referenced if the site was set to use a right-to-left language (the best practice is to create a style sheet called
rtl.css which does this automatically). Other extras include
after although these are used more by WordPress internally for setting the reference to a minified / non-minified file, and for setting internal style sheet data to appear after a specific external style sheet reference via
Since the name of the extra key is not fixed, you could add some of your own arbitrary meta data to associate with an enqueued style sheet (remember to prefix the key so you avoid any potential clashes with WordPress-supported keys in the future).