[wp-trac] [WordPress Trac] #21766: modify body_class function to allow non-class items

WordPress Trac wp-trac at lists.automattic.com
Sat Sep 1 18:11:44 UTC 2012


#21766: modify body_class function to allow non-class items
--------------------------+------------------------------------------------
 Reporter:  norcross      |      Owner:
     Type:  feature       |     Status:  new
  request                 |  Milestone:  Awaiting Review
 Priority:  normal        |    Version:  trunk
Component:  General       |   Keywords:  has-patch dev-feedback 2nd-opinion
 Severity:  normal        |
--------------------------+------------------------------------------------
 Currently, the `body_class` only allows for filtering with additional
 classes. For users that want to add other items, they have to manually
 edit the theme files. The best example of this is schema.org body elements
 (itemtype and itemprop).

 The diff file shows two things:

 1. the new `body_items` function that grabs any items added via filter, if
 they exist.

 2. the modified `body_class` function, which appends the output with the
 items if they exist.

 The patch, as I've written it, allows for this additional filter to be
 included without interfering with how themes / plugins interact with the
 current `body_class` filter, and doesn't require theme authors to include
 an additional tag in their themes.

 Below is an example function that could be placed in a theme or plugin to
 add other items to the body tag element.


 {{{
 function schema_bodyitems($item) {

         if (is_page() ) :
                 $item[] = 'item-foo="item-bar"';
         endif;

         $item[] = 'itemtype="http://schema.org/Blog"';
         $item[] = 'itemscope=""';

 return $item;
 }

 add_filter('body_items','schema_bodyitems');
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/21766>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list