Placing Custom Classes inside Child Theme
-
Hopefully you can help me with this. I have created a child theme of your shapla parent theme and everything is working fine but I wanted to have the extra custom page named home-page.php in the page attributes meta box where you have placed options for default template, full screen and full width templates.
I made the changes to your inc/class-shapla.php file and created the custom page based on your full screen page. Everything works fine when using inside your parent theme. But it won’t work when I try to incorporate into my child theme.
This is what I added to your inc/class-shapla.php file:
/** * Adds custom classes to the array of body classes. * * @param array $classes Classes for the body element. * * @since 0.1.0 * @return array */ public function body_classes( $classes ) { // Adds a class of group-blog to blogs with more than 1 published author. if ( is_multi_author() ) { $classes[] = 'group-blog'; } // Adds a class of hfeed to non-singular pages. if ( ! is_singular() ) { $classes[] = 'hfeed'; } if( is_page_template( 'templates/full-width.php' ) ) { $classes[] = 'full-width'; } if( is_page_template( 'templates/full-screen.php' ) ) { $classes[] = 'full-screen'; } if( is_page_template( 'templates/home-page.php' ) ) { $classes[] = 'full-screen'; } // If our main sidebar doesn't contain widgets, // adjust the layout to be full-width. if ( ! is_active_sidebar( 'sidebar-1' ) ) { $classes[] = 'no-sidebar'; } $classes[] = 'shapla'; return $classes; }
This is what I added to my functions.php file in the child theme after removing the code for the home-page.php template from your inc/class-shapla.php file:
/** * Adds custom classes to the array of body classes. * * @param array $classes Classes for the body element. * * @since 0.1.0 * @return array */ public function body_classes( $classes ) { // Adds a class of group-blog to blogs with more than 1 published author. if ( is_multi_author() ) { $classes[] = 'group-blog'; } // Adds a class of hfeed to non-singular pages. if ( ! is_singular() ) { $classes[] = 'hfeed'; } if( is_page_template( 'templates/home-page.php' ) ) { $classes[] = 'full-screen'; } // If our main sidebar doesn't contain widgets, // adjust the layout to be full-width. if ( ! is_active_sidebar( 'sidebar-1' ) ) { $classes[] = 'no-sidebar'; } $classes[] = 'shapla'; return $classes; }
For some reason it is not working when adding to my child theme functions.php file. What am I missing? Can this even be done inside a child theme with your shapla theme as the parent. Otherwise I would have to update the inc/class-shapla.php file every time you udpate your theme. Thanks for the support.
- The topic ‘Placing Custom Classes inside Child Theme’ is closed to new replies.