Last active
March 27, 2025 17:08
-
-
Save mattradford/5147ca70e8c63cb070de to your computer and use it in GitHub Desktop.
Add home link to start or end of menu
From http://wordpress.stackexchange.com/questions/121309/how-do-i-programatically-insert-a-new-menu-item
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Filter wp_nav_menu() to add additional links and other output | |
function new_nav_menu_items($items) { | |
$homelink = '<li class="home"><a href="' . home_url( '/' ) . '">' . __('Home') . '</a></li>'; | |
// add the home link to the end of the menu | |
$items = $items . $homelink; | |
return $items; | |
} | |
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items' ); | |
or add_filter( 'wp_nav_menu_{$menu->slug}_items', 'new_nav_menu_items' ); | |
e.g. add_filter( 'wp_nav_menu_primary-navigation_items', 'new_nav_menu_items' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment