Community Forums › Forums › Archived Forums › General Discussion › Changing Genesis menu.php to add RSS icon
Tagged: adding menu items, menu.php, navigation
- This topic has 4 replies, 2 voices, and was last updated 10 years, 8 months ago by cambrosi.
-
AuthorPosts
-
August 15, 2013 at 12:08 pm #56613cambrosiMember
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.comAugust 15, 2013 at 12:30 pm #56615Brad DaltonParticipantAugust 15, 2013 at 1:07 pm #56626cambrosiMemberThanks, 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 menuif ( '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;
}August 15, 2013 at 1:27 pm #56634Brad DaltonParticipantAt the end of the file however you would need to modify the code to extend it. I would test locally first.
August 15, 2013 at 3:54 pm #56678cambrosiMemberThanks 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; }
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.