Opened 20 months ago
Last modified 4 weeks ago
#18753 new enhancement
Add data to stylesheets
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Template | Version: | |
| Severity: | normal | Keywords: | has-patch 2nd-opinion |
| Cc: | Ken@…, philip@… |
Description
In my humble opinion it would be awesome to provide theme developers an easy function to add extra data to registered stylesheets.
This way they could use the 'wp_head' action to cleanly make stylesheets conditional for IE, make them alternate or add RTL support.
Like wp_add_inline_style(), this function could really contribute to decluttering template files.
Attachments (1)
Change History (9)
This exists currently, but you have to dig into $wp_styles and use add_data(), such as add_data( 'ie', 'conditional', 'lte IE 7' ) and add_data( $handle, 'rtl', true );.
It's complex (I didn't provide a code sample as I'd have to look it up beyond what I provided) and I wouldn't mind some wrappers here.
comment:4
WraithKenny — 10 months ago
- Cc Ken@… added
@kobenland I like the goal of this idea. I also feel that the script/style system is more complex that it needs to be and it needs to be simplified. I think it would be better to implement a more general data method that could be used for many purposes rather than adding a function that only gets used a few times. A function like the example below would be capable of storing data related to scripts/styles and practically anything else. Also (loosely related) see #22249
// Get or set data via key/value pair.
function wp_data ($k = null, $v = null) {
static $hash; // php.net/manual/en/language.variables.scope.php
isset($hash) or $hash = array(); // only initiates once
if ( func_num_args() > 1 )
return $hash[$k] = $v; // set
if ( is_scalar($k) )
return $hash[$k]; // get
if ( is_null($k) )
return $hash; // get all
return $hash = array_merge($hash, (array) $k); // set multi
}
Replying to ryanve:
@kobenland I like the goal of this idea. I also feel that the script/style system is more complex that it needs to be and it needs to be simplified. I think it would be better to implement a more general data method that could be used for many purposes rather than adding a function that only gets used a few times.
I appreciate your feedback! I merely proposed an abstraction of existing functionality though. Maybe it would be a good idea to open a new ticket with what you came up with?
- Cc philip@… added

Patch