56 | Twenty Eleven – New Page Template with Sidebar Correction

0

If you are creating a new page template for a child theme of Twenty Eleven, with a sidebar, you need to correct the body_class output to remove the css class .singular.

Add this to functions.php of your child theme:

add_filter('body_class', 'adjust_body_class', 20, 2);
function adjust_body_class($wp_classes, $extra_classes) { 

if( is_page_template('new-sidebar-page-template-file-name.php') ) :
// Filter the body classes     

	  foreach($wp_classes as $key => $value) {
	  if ($value == 'singular') unset($wp_classes[$key]);
	  }

endif;
// Add the extra classes back untouched
return array_merge($wp_classes, (array) $extra_classes );
}

If you created more than one new page template with sidebar, change this one line in the code to something like:

if( is_page_template('new-sidebar-page-template-file-name.php') || is_page_template('another-sidebar-page-template.php') || is_page_template('further-sidebar-page-template.php') ) :

The above codes are similar to what I used in this recent article.

This entry was posted in Tips & Tricks, TwentyEleven. Bookmark the permalink.

One Response to Twenty Eleven – New Page Template with Sidebar Correction

  1. Pingback: WordPress Community Roundup for the Week Ending January 21 - Charleston WordPress User Group

    0

    January 24, 2012 | [...] Twenty Eleven – New Page Template with Sidebar Correction [...]

Leave a Reply

Your email address will not be published.

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>