• I keep getting this error. It doesn’t always appear, but about 50% of the time, both on the front end AND the back end.

    I am using a child theme (twenty-thirteen-child). It seems like the functions.php of the parent and the child themes are interfering..? Shouldn’t the child’s functions.php completely override that of the parent?

    Fatal error: Cannot redeclare twentythirteen_setup() (previously declared in /home/content/20/11764620/html/wordpress/wp-content/themes/twentythirteen-child/functions.php:69) in /home/content/20/11764620/html/wordpress/wp-content/themes/twentythirteen/functions.php on line 104

Viewing 5 replies - 1 through 5 (of 5 total)
  • Did you copy the parent’s function.php file into the child theme?

    Thread Starter seanfilidis

    (@seanfilidis)

    I did. I now realize you can’t do that. The child theme’s functions.php should only contain new functions.

    But I have a problem then. I am using the functions.php to create an additional sidebar. I just deleted everything in the functions.php except for this function. But I still get a similar error.

    Here is the code in my child theme’s functions.php:

    <?php
    
    if ( ! function_exists( 'twentythirteen_widgets_init' ) ) {
    
    function twentythirteen_widgets_init() {
    	register_sidebar( array(
    		'name'          => __( 'Main Widget Area', 'twentythirteen' ),
    		'id'            => 'sidebar-1',
    		'description'   => __( 'Appears in the footer section of the site.', 'twentythirteen' ),
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h3 class="widget-title">',
    		'after_title'   => '</h3>',
    	) );
    
    	register_sidebar( array(
    		'name'          => __( 'Secondary Widget Area', 'twentythirteen' ),
    		'id'            => 'sidebar-2',
    		'description'   => __( 'Appears on posts and pages in the sidebar.', 'twentythirteen' ),
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h3 class="widget-title">',
    		'after_title'   => '</h3>',
    	) );
    
    	register_sidebar( array(
    		'name'          => __( 'Third Widget Area', 'twentythirteen' ),
    		'id'            => 'sidebar-3',
    		'description'   => __( 'Is only for the front page.', 'twentythirteen' ),
    		'before_widget' => '<aside id="%1$s" class="widget widget-fp1">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h3 class="widget-title">',
    		'after_title'   => '</h3>',
    	) );
    }
    }
    
    ?>

    As you can see I just added a third sidebar. However I now get this fatal error message:

    Fatal error: Cannot redeclare twentythirteen_widgets_init() (previously declared in /home/content/20/11764620/html/wordpress/wp-content/themes/twentythirteen-child/functions.php:7) in /home/content/20/11764620/html/wordpress/wp-content/themes/twentythirteen/functions.php on line 245

    Thread Starter seanfilidis

    (@seanfilidis)

    From what I read, putting that conditional in the beginning should prevent the problem, but it doesn’t seem to be working.

    You have to create a custom function to add a 3rd sidebar and then hook it using add_action( 'widgets_init', 'custom_function_name' );

    Thread Starter seanfilidis

    (@seanfilidis)

    Presto! Thanks.
    My code now looks like this

    <?php
    
    function twentythirteenchild_widgets_init() {
    
    	register_sidebar( array(
    		'name'          => __( 'Third Widget Area', 'twentythirteen' ),
    		'id'            => 'sidebar-3',
    		'description'   => __( 'Is only for the front page.', 'twentythirteen' ),
    		'before_widget' => '<aside id="%1$s" class="widget widget-fp1">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h3 class="widget-title">',
    		'after_title'   => '</h3>',
    	) );
    }
    
    add_action( 'widgets_init', 'twentythirteenchild_widgets_init' );
    
    ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Fatal Error Cannot Redeclare’ is closed to new replies.