Skip to content

Instantly share code, notes, and snippets.

@rfmeier
Last active October 29, 2018 14:36
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rfmeier/5735579 to your computer and use it in GitHub Desktop.
Save rfmeier/5735579 to your computer and use it in GitHub Desktop.
Add custom nav item to Genesis primary menu
<?php
//* do no include php tags
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, $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( '<li class="right your-custom-code-class">%s</li>', __( 'Your custom code' ) );
return $menu;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment