Changing Genesis menu.php to add RSS icon

Community Forums Forums General Discussion Changing Genesis menu.php to add RSS icon

This topic is: not resolved

This topic contains 4 replies, has 2 voices, and was last updated by  cambrosi 1 year, 2 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #56613

    cambrosi
    Participant
    Post count: 7

    Hi, I used to add the following code snippet to Genesis structure/menu.php to add an RSS icon to the end of the nav menu (after the Twitter icon):

    $nav_output = sprintf( ‘<div id=”nav”>%2$s%1$s%3$s</div>’, $nav, genesis_structural_wrap( ‘nav’, ‘<div class=”rss”></div><div class=”wrap”>’, 0 ), genesis_structural_wrap( ‘nav’, ‘</div><!– end .wrap –>’, 0 ) );

    The reason I did this was because adding the menu item inside WordPress Menus put the icon on a second row by itself.
    But with the latest update the menu.php code has changed and I can’t figure out how to add my snippet back in. Quite frankly, I don’t even remember how I figured this out in the first place.

    I would appreciate any suggestions!

    http://mediamikes.com
    #56615

    braddalton
    Participant
    Post count: 10357
    #56626

    cambrosi
    Participant
    Post count: 7

    Thanks, Brad. I tried adding this code and I took out the site. Does it go under the
    require_once( dirname( __FILE__ ) . ‘/lib/init.php’ );
    in functions.php?

    add_filter( ‘wp_nav_menu_items’, ‘custom_nav_item’, 10, 2 );
    /**
    * Callback for Genesis ‘wp_nav_menu_items’ filter.
    *
    * Add custom right nav item to Genesis primary menu.
    *
    * @package Genesis
    * @category Nav Menu
    * @author Ryan Meier http://www.rfmeier.net
    *
    * @param string $menu The menu html
    * @param stdClass $args the current menu args
    * @return string $menu The menu html
    */

    function custom_nav_item( $menu, stdClass $args ){
    // make sure we are in the primary menu

    if ( ‘primary’ != $args->theme_location )
    return $menu;

    // see if a nav extra was already specified with Theme options
    if( genesis_get_option( ‘nav_extras’ ) )
    return $menu;

    // additional checks?

    // append your custom code

    $menu .= sprintf( ‘<div id=”nav”>%2$s%1$s%3$s</div>’, $nav, genesis_structural_wrap( ‘nav’, ‘<div class=”rss”></div><div class=”wrap”>’, 0 ), genesis_structural_wrap( ‘nav’, ‘</div><!– end .wrap –>’, 0 ) );

    // return the menu

    return $menu;
    }

    #56634

    braddalton
    Participant
    Post count: 10357

    At the end of the file however you would need to modify the code to extend it. I would test locally first.


    #56678

    cambrosi
    Participant
    Post count: 7

    Thanks for your help. I ended modifying the rss case in this function in menu.php, and then tweaking the styles:

    
    function genesis_nav_right( $menu, stdClass $args ) {
    
    	if ( ! genesis_get_option( 'nav_extras' ) || 'primary' !== $args->theme_location )
    		return $menu;
    
    	switch ( genesis_get_option( 'nav_extras' ) ) {
    		case 'rss':
    			$rss   = '<a rel="nofollow" href="' . get_bloginfo( 'rss2_url' ) . '"></a>';
    			$menu .= '<li class="right rss">' . $rss . '</li>';
    			break;
    		case 'search':
    			// I hate output buffering, but I have no choice
    			ob_start();
    			get_search_form();
    			$search = ob_get_clean();
    			$menu  .= '<li class="right search">' . $search . '</li>';
    			break;
    		case 'twitter':
    			$menu .= sprintf( '<li class="right twitter"><a href="%s">%s</a></li>', esc_url( 'http://twitter.com/' . genesis_get_option( 'nav_extras_twitter_id' ) ), esc_html( genesis_get_option( 'nav_extras_twitter_text' ) ) );
    			break;
    		case 'date':
    			$menu .= '<li class="right date">' . date_i18n( get_option( 'date_format' ) ) . '</li>';
    			break;
    	}
    
    	return $menu;
    
    }
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.