• Resolved silentblossom

    (@silentblossom)


    Hello I am using a child theme and i need to add another menu to the template. When I add the following to the new functions.php file in my child theme, i get an error.

    <?php
    function register_main_menus() {
    
    	register_nav_menus(
    
    		array(
    
    			'primary-menu' => __( 'Primary Menu' ),
    
    			'secondary-menu' => __( 'Secondary Menu'),
    
    			'tertiary-menu' => __( 'Tertiary Menu'),
    
    		)
    
    	);
    
    }
    
    if (function_exists('register_nav_menus')) add_action( 'init', 'register_main_menus' );?>

    I know i am not doing this right but I do not know how to fix it. Please help. The error is below thanks!

    Fatal error: Cannot redeclare register_main_menus() (previously declared in /home/content/c/o/m/companyserver/html/rajwa2/wp-content/themes/ChildOfChameleon/functions.php:8) in /home/content/c/o/m/companyserver/html/rajwa2/wp-content/themes/Chameleon/functions.php on line 46

Viewing 4 replies - 1 through 4 (of 4 total)
  • change function name from register_main_menus to register_main_menus1 and check if it work?

    This is what I use and it still worked last time I checked.

    //This is from Justin Tadlock 
    
    add_action( 'init', 'register_my_menus' );
    
    function register_my_menus() {
    	register_nav_menus(
    		array(
    			'primary-menu' => __( 'Primary Menu' ),
    			'secondary-menu' => __( 'Secondary Menu' ),
    			'tertiary-menu' => __( 'Tertiary Menu' )
    		)
    	);
    }
    Thread Starter silentblossom

    (@silentblossom)

    Thanks so much! I tried the code above but for some reason, the code shows above the website as text. I am also getting this error in wordpress

    add_action( 'init', 'register_my_menus' ); function register_my_menus() { register_nav_menus( array( 'primary-menu' => __( 'Primary Menu' ), 'secondary-menu' => __( 'Secondary Menu' ), 'tertiary-menu' => __( 'Tertiary Menu' ) ) ); }
    Warning: Cannot modify header information - headers already sent by (output started at /home/content/c/o/m/companyserver/html/rajwa2/wp-content/themes/ChildOfChameleon/functions.php:11) in /home/content/c/o/m/companyserver/html/rajwa2/wp-admin/theme-editor.php on line 103

    Any suggestions?

    Thread Starter silentblossom

    (@silentblossom)

    I realized what i was doing wrong!! In the new functions.php file, i needed to remove the 'primary-menu' => __( 'Primary Menu' ), as it already existed in the main functions file. It works now!

    Thank you all for support!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How do I add a new menu using a child theme?’ is closed to new replies.