WordPress.org

Ready to get started?Download WordPress

Forums

Twenty Twelve
[resolved] Problem with overriding parent theme functions (4 posts)

  1. Ruud Evers
    Member
    Posted 1 year ago #

    Hi all,

    I'm creating a child theme for 2012 and need to adjust 2012's body_class function as declared in 2012's functions.php. I've tried a couple of solutions, but without success. My last try was this:

    function adjust_twentytwelve_body_class( $classes ) {
    	// the adjusted function
    }
    remove_filter( 'body_class', 'twentytwelve_body_class' );
    add_filter( 'body_class', 'adjust_twentytwelve_body_class' );

    Any ideas?

  2. What's the body class you want to remove or add?

    For example if you want to remove the full-width body class then this works well.

    add_filter('body_class','twentytwelvechild_body_classes',20);
    function twentytwelvechild_body_classes( $classes ) {
    	foreach($classes as $key => $value) {
    		if ($value == 'full-width') unset($classes[$key]);
    	}
    	return $classes;
    }

    See alchymyth's example here http://wordpress.org/support/topic/twenty-twelve-hardcode-sidebar?replies=13#post-3615651

    Adding classes works also.

    // Add specific CSS class by filter
    add_filter('body_class','my_class_names');
    function my_class_names($classes) {
    	// add 'class-name' to the $classes array
    	$classes[] = 'class-name';
    	// return the $classes array
    	return $classes;
    }

    See http://codex.wordpress.org/Function_Reference/body_class#Add_Classes_By_Filters for more examples.

  3. Ruud Evers
    Member
    Posted 1 year ago #

    Removing the full-width body class was exactly what I needed. Thanks.

    I also found a solution in this thread: http://wordpress.org/support/topic/overriding-twentytwelve_wp_title-in-a-child-theme?replies=5, as I see, from the same guy. This worked for overriding the parent's functions.

  4. Glad to help especially when all I did was recycle alchymyth's reply. ;)

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic