WordPress Snippets at WPcustoms

Add menu link to custom menu locations

Manually add menu links to a custom menu location with this snippet. Adjust your menu name as stated within the after_setup_theme registration function.


/**
 * Snippet Name: Add menu link to custom menu locations
 * Snippet URL: https://wpcustoms.net/snippets/add-menu-link-to-custom-menu-locations/
 */
  function wpc_new_nav_menu_items($items, $args) {
    if( $args->theme_location == 'primary_navigation' ){ // update your menu location name here
        $homelink = '
  • ' . __('Home') . '
  • '; $items = $homelink . $items; } return $items; } add_filter( 'wp_nav_menu_items', 'wpc_new_nav_menu_items', 10, 2 );