Support » Fixing WordPress » How to delete .page class from body on one page template?

  • Hello,

    I’ve got a problem here..

    WordPress does some freaking ugly body class including that i would like to change.


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

    Ends up like this:

    <body class="page page-id-20 page-template page-template-page-300-php">

    This makes me very sad at the moment and i would like to delete the page class from only one page-template file. (portfolio.php)

    I’ve made a few different page templates like: 300 layout, 600 layout, portfolio layout, homepage layout, archive, search, 404 you name it.

    Now i’ve got this problem when viewing my site on a mobile device i would like to hide a column with images that aren’t very important to my layout to clear some space, but on my portfolio template this column with included images are indeed very !important! to display because thats my work stuff.
    How could i only hide the page body class from only my page template portfolio.php ?

    After that i could easily go inside my mobile divide stylesheet and hide the .page class like this:


    .page .column-2 { display: none; }

    Else i have to write 25 lines of CSS code to exclude all custom made templates files.

Viewing 4 replies - 1 through 4 (of 4 total)
  • in functions.php of your theme, add:

    add_filter('body_class', 'remove_a_body_class', 20, 2);
    function remove_a_body_class($wp_classes) {
    if( is_page_template('portfolio.php') ) :
          foreach($wp_classes as $key => $value) {
          if ($value == 'page') unset($wp_classes[$key]);
    return $wp_classes;

    alternatively, you could try to do it all with css: .column-2 { display: block; }

    Thread Starter Jaja..


    Thank you so much!

    This helps a lot..

    Just trying to understand the PHP code what does , 20, 2 stand for?
    Exclude ID’s ?

    Moderator Ipstenu (Mika Epstein)


    🏳️‍🌈 Plugin Review Team Rep

    The 20 is for priority, the 2 is for how many arguments are accepted.

    Thread Starter Jaja..


    Okay cool..

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to delete .page class from body on one page template?’ is closed to new replies.