The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

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

  1. Ruude4s
    Posted 3 years 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.

    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
    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. Ruude4s
    Posted 3 years 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