WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WordPress 3.2 body_class function is missing "page-template-default" class (8 posts)

  1. kyleduncan
    Member
    Posted 3 years ago #

    Hi,

    I just upgraded a site to 3.2 which made use of the CSS class "page-template-default" on all pages that had no page template selected. This class doesn't seem to be rendered anymore on pages, although all other body classes seem fine.

    Is this deliberate or a bug?

    Thanks in advance for any help.

    Kyle Duncan

  2. Did you change your theme? Nothing in trac indicates this has been removed.

  3. kyleduncan
    Member
    Posted 3 years ago #

    Hi,

    No it was a custom written theme with this in header.php:

    <body <?php body_class( $class ); ?>>

    Before this generated "page-template-default" as one of the many classes on pages with no template selected. it used to look like this:

    <body class="page page-id-10 page-template page-template-default">

    now, on those pages, just the following is generated:

    <body class="page page-id-10">

  4. esmi
    Forum Moderator
    Posted 3 years ago #

    Why would you need "page-template-default" on the body element?

  5. Dion Hulse
    WordPress Dev
    Posted 3 years ago #

    it used to look like this:

    <body class="page page-id-10 page-template page-template-default">

    now, on those pages, just the following is generated:

    <body class="page page-id-10">

    This was fixed back in 2.8.1, The class was never supposed to be added when no page template was specified. See [11567] and the ticket mentioned in that commit

  6. Dion Hulse
    WordPress Dev
    Posted 3 years ago #

    Sorry scrap that, Yes, that caused a similar bug back in 2.8, however, that's not what caused it.

    It was a bug that the page-template-default was ever shown. See #17458 for details.

  7. Peter Wilson
    Member
    Posted 3 years ago #

    @kyleduncan If you want it back, adding this to your themes functions.php file will do so.

    function mytheme_body_class_template_default($classes) {
      if (is_page() AND !is_page_template()) { $classes[] = 'page-template-default'; }
      return $classes;
    }
    add_filter('body_class', 'mytheme_body_class_template_default');

    @esmi It's a handy css hook to use if each page template has a very different layout.

  8. kyleduncan
    Member
    Posted 3 years ago #

    Thanks to all for the explanations.

Topic Closed

This topic has been closed to new replies.

About this Topic