[wp-trac] [WordPress Trac] #36391: Create a hook to handle plugin CSS?

WordPress Trac noreply at wordpress.org
Fri Apr 1 00:12:27 UTC 2016


#36391: Create a hook to handle plugin CSS?
-----------------------------+-----------------------------
 Reporter:  CarlosRios       |      Owner:
     Type:  feature request  |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  Script Loader    |    Version:  trunk
 Severity:  normal           |   Keywords:
  Focuses:  performance      |
-----------------------------+-----------------------------
 I'm not sure if this has been suggested before, but it would be really
 cool if there was a hook for plugins that would allow them to add their
 css to a css file that is generated and enqueued automatically when that
 hook is not empty.

 This would be done to prevent plugins such as Visual Composer, from
 loading all of their custom css in the <head> of the page which can be bad
 for caching. Instead they would hook in, add their css, and then the css
 would be added to a single file along with all of the other css that has
 been hooked to it.


 {{{
 add_filter( 'options_css', 'add_my_plugin_css' );
 function add_my_plugin_css( $hooked_css ) {
    $bg_color = get_option( 'header_background_color' );
    $hooked_css .= '#header{background-color:'.$bg_color.';}';
    return $hooked_css;
 }
 }}}

 This code would then be hooked, sanitized, and minified, and then enqueued
 where it needs to be. I'd even suggest that the name of the css file could
 be wp-options.css or options.css

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36391>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list