• Hi there,

    I’m looking for the best way to “clean” the body classes generated by WordPress by default, through functions.php. I’ve found an interesting way to do it here:

    https://github.com/billerickson/EA-Genesis-Child/blob/master/inc/wordpress-cleanup.php

    Getting the following classes :
    ‘singular’,
    ‘single’,
    ‘page’,
    ‘archive’,
    ‘admin-bar’,
    ‘full-width-content’,
    ‘content-sidebar’,
    ‘content’,
    is already nice but it’s a bit restrictive because I’d like to authorize classes like .page-*** dynamically for every new page created.

    Is using something like :
    $dynamic_pages = "page-". $dynamic_pages;
    is a good way to achieve it?

    Thanks by advance for your help !

Viewing 3 replies - 1 through 3 (of 3 total)
  • You seem to be contradicting yourself, as you want to clean the classes but then you want to add more?

    I do not see any benefit in removing any classes that WordPress adds, and the theme and plugins add the ones they need.
    If you have a use for an additional class, structure it the way you need. I would not use page- as a prefix, because it is already used by WordPress, and is specific to Pages.

    In my theme, I add a class to represent each post, by using its slug with a prefix of ‘name-‘ because that’s the variable name of the slug (post_name).
    My theme also provides a way to apply theme options per page, and I use the body classes to do this.

    Thread Starter Obje

    (@harrow)

    Hi Joy,

    Thank you for your reply.
    The only reason I do that is to keep my code as clear as possible.
    Having classes like :
    “home page-template-default page page-id-90 single-author singular not-logged-in weaver-desktop weaver-mobile-smart-stacked” doesn’t make any sens to me when “home” is the only class I need to target my homepage with css.

    So that’s why I’d like to delete all unusued classes, but when a new page is added by the administrator, keep the ability for WordPress to add dynamically page-slug-of-the-page .

    But you don’t know if your theme or plugins are using those classes, which they might be, especially the ‘not-logged-in’ one. They certainly don’t hurt anything.
    I know for a fact that the Weaver theme uses the weaver classes, even in javascript.

    And like I said, page- is used by WP already, so that’s not a good choice for your new class.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Body class cleaning’ is closed to new replies.