[wp-trac] [WordPress Trac] #31398: Add theme function add_body_class() to abstract filtering `body_class`

WordPress Trac noreply at wordpress.org
Fri Feb 20 20:15:11 UTC 2015


#31398: Add theme function add_body_class() to abstract filtering `body_class`
---------------------------------+-----------------------------
 Reporter:  mattheweppelsheimer  |      Owner:
     Type:  enhancement          |     Status:  new
 Priority:  normal               |  Milestone:  Awaiting Review
Component:  Themes               |    Version:
 Severity:  normal               |   Keywords:
  Focuses:  template             |
---------------------------------+-----------------------------
 I frequently filter {{{body_class}}} at the top of page templates to
 support shared template parts, to set up those template parts' custom CSS
 and/or JavaScript. So I end up with a lot of this pattern at the top of
 templates:

 {{{#!php
 add_filter('body_class', 'my_new_body_class');
 function my_new_body_class( $classes ) {
         $classes[] = 'foo';
         return $classes;
 }
 }}}

 I'd like to do something like this, instead: {{{wp_add_body_class( 'foo'
 );}}}.

 This function would wrap the mechanism above. It would accept an array or
 a string. The advantage is speed of writing theme templates in this way,
 and simplicity in reading the code.

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


More information about the wp-trac mailing list