Working on a child theme for site with a good deal of separate stylesheets being registered/enqueued from the theme and plugins. I'd like to change some attributes of the
<link> tags in the final output, while avoiding conflicts after a parent theme update by the site owner.
The goal is to not re-register/re-enqueue the same
.css files already set by the parent theme and/or plugins, while effectively passing a new set of arguments to the
For example, currently this is what the parent theme & plugins are doing:
// parent theme or plugin's php wp_register_style( 'a_stylesheet', $uri . 'css/a-stylesheet.css', array(), $version, 'screen' ); // html output <link rel='stylesheet' id='a_stylesheet-css' href='http://domain.com/wp-content/themes/theme/css/a-stylesheet.css' type='text/css' media='screen' />
The goal is for the child theme to in effect change the
wp_register_style call, like so:
// child theme's php some_function_to_reregister( 'already_registered_file', $inherit, $inherit, $inherit, 'handheld' ) // if the above doesn't exist, do nothing; else, re-register with the new argument(s). // html output <link rel='stylesheet' id='a_stylesheet-css' href='http://domain.com/wp-content/themes/theme/css/a-stylesheet.css' type='text/css' media='handheld' />
This changes the
<link media> attribute to
handheld instead of
screen, but preserves everything else being done by the parent theme/plugin, and skips registering the file if it hasn't been registered yet elsewhere (i.e. after an update).
Seems like this would be a much more efficient approach than de-registering/de-enqueuing css from the parent theme and plugins only to copy/paste it back in the child theme and have unexpected wreckage in future updates.