0

I'm moving on from the child of a (no-longer serviced) 2009 theme to a child of twenty sixteen - I previously had a code in my functions that generated the week number as a body class - e.g w32 (for this week for example.)

I'm using the following code in my old theme but of course it no longer functions in twenty sixteen. Are there any tips to implement it there? The following is in the functions.php of my child folder:

// Adds 'week' and parent-page id body-class

add_filter( 'hybrid_body_class', 'my_body_class' );

function my_body_class( $class ) {
    global $wp_query;

    $time = time() + ( get_option( 'gmt_offset' ) * 3600 );
    $class .= ' w' . gmdate( 'W', $time );

    if ( is_page() && $wp_query->post->post_parent )
        $class .= ' parent-' . $wp_query->post->post_parent;

    return $class;
}

As I'm no longer using the hybrid theme, I've tried changing hybrid_body_class to body_class and multiple other variants - to no avail or with errors...

0

Twentysixteen's header and functions.php appear to support the body_class filter.

add_filter('body_class', 'my_body_classes');

function my_body_classes($classes) {

        global $wp_query;

        $time = time() + ( get_option( 'gmt_offset' ) * 3600 );
        $classes[] = 'w' . gmdate( 'W', $time );

        if ( is_page() && $wp_query->post->post_parent ){
             $classes[] = 'parent-' . $wp_query->post->post_parent;
        }

        return $classes;
}
  • Brilliant - thanks jgraup - wordpress-stack is my new reference - as an oldie I was still using stack exchange ;-) – billn Aug 14 '16 at 20:45
  • Great. Glad it worked out for you. – jgraup Aug 14 '16 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.