• i would like to add a third level menu on wordpress, this is the code i’ve added to the function.php to create the secondary menu, but when i’m trying to repeat the same code with a third menu, i get an error.

    add_action( ‘init’, ‘my_custom_menus’ );
    function my_custom_menus() {
    register_nav_menus(
    array(
    ‘primary-menu’ => __( ‘Primary Menu’ ),
    ‘secondary-menu’ => __( ‘Secondary Menu’ )

    Help?

Viewing 5 replies - 1 through 5 (of 5 total)
  • What error are you getting? Also, the code you’re posting here looks incomplete. Can you post the complete piece of code you’re using to register your menus?

    Thread Starter ethan.com

    (@ethancom)

    Hi, thank u for your help,
    I’m getting this error:

    Parse error: syntax error, unexpected ”third-menu” (T_CONSTANT_ENCAPSED_STRING), expecting ‘)’ in /home/eliorc/public_html/wp-content/themes/wt_metro/functions.php on line 79

    (also in order to fix it i have to go to the files on the host and to change it back)

    The complete code:

    <?php
    require( get_template_directory() . '/framework/functions.php' );
    
    /**
     * Set the format for the more in excerpt, return ... instead of [...]
     */
    function wellthemes_excerpt_more( $more ) {
    	return '...';
    }
    add_filter('excerpt_more', 'wellthemes_excerpt_more');
    
    function wt_time_ago() {
    
    	global $post;
    
    	$date = get_post_time('G', true, $post);
    
    	// Array of time period chunks
    	$chunks = array(
    		array( 60 * 60 * 24 * 365 , __( 'year', 'wellthemes' ), __( 'years', 'wellthemes' ) ),
    		array( 60 * 60 * 24 * 30 , __( 'month', 'wellthemes' ), __( 'months', 'wellthemes' ) ),
    		array( 60 * 60 * 24 * 7, __( 'week', 'wellthemes' ), __( 'weeks', 'wellthemes' ) ),
    		array( 60 * 60 * 24 , __( 'day', 'wellthemes' ), __( 'days', 'wellthemes' ) ),
    		array( 60 * 60 , __( 'hour', 'wellthemes' ), __( 'hours', 'wellthemes' ) ),
    		array( 60 , __( 'minute', 'wellthemes' ), __( 'minutes', 'wellthemes' ) ),
    		array( 1, __( 'second', 'wellthemes' ), __( 'seconds', 'wellthemes' ) )
    	);
    
    	if ( !is_numeric( $date ) ) {
    		$time_chunks = explode( ':', str_replace( ' ', ':', $date ) );
    		$date_chunks = explode( '-', str_replace( ' ', '-', $date ) );
    		$date = gmmktime( (int)$time_chunks[1], (int)$time_chunks[2], (int)$time_chunks[3], (int)$date_chunks[1], (int)$date_chunks[2], (int)$date_chunks[0] );
    	}
    
    	$current_time = current_time( 'mysql', $gmt = 0 );
    	$newer_date = strtotime( $current_time );
    
    	// Difference in seconds
    	$since = $newer_date - $date;
    
    	// Something went wrong with date calculation and we ended up with a negative date.
    	if ( 0 > $since )
    		return __( 'sometime', 'wellthemes' );
    
    	/**
    	 * We only want to output one chunks of time here, eg:
    	 * x years
    	 * xx months
    	 * so there's only one bit of calculation below:
    	 */
    
    	//Step one: the first chunk
    	for ( $i = 0, $j = count($chunks); $i < $j; $i++) {
    		$seconds = $chunks[$i][0];
    
    		// Finding the biggest chunk (if the chunk fits, break)
    		if ( ( $count = floor($since / $seconds) ) != 0 )
    			break;
    	}
    
    	// Set output var
    	$output = ( 1 == $count ) ? '1 '. $chunks[$i][1] : $count . ' ' . $chunks[$i][2];
    
    	if ( !(int)trim($output) ){
    		$output = '0 ' . __( 'seconds', 'wellthemes' );
    	}
    
    	$output .= __(' ago', 'wellthemes');
    
    	return $output;
    }
    
    add_action( 'init', 'my_custom_menus' );
          function my_custom_menus() {
             register_nav_menus(
                array(
          'primary-menu' => __( 'Primary Menu' ),
          'secondary-menu' => __( 'Secondary Menu' )
                        )
                 );
          }
    ?>

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    The error mentions an unexpected “third-menu” string, but that is not present in your code. Please paste the exact code that is triggering the error, so we can detect where the problem is exactly.

    However, it sounds to me like a missing comma into the array you’re passing to register_nav_menus(). The correct code should look like this:

    register_nav_menus(
    	array(
    		'primary-menu' => __( 'Primary Menu' ),
    		'secondary-menu' => __( 'Secondary Menu' ),
    		'third-menu' => __( 'Third Menu' ),
    	)
    )

    I don’t know about your level of PHP coding, so this may sound silly, but please note that after every element of an array you must put a comma if you want to declare a new element. The comma after the last element, as it shows in my example, is optional.

    Thread Starter ethan.com

    (@ethancom)

    I took out the “third-menu” before I’ve posted this question, but you’re right! the problem was the comma:) (I am pretty new to PHP coding).
    You are the BEST!
    Thank you so much for helping me and good luck:)

    Great to see that it solved the problem 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add Third Menu Bar’ is closed to new replies.