Custom Static Links For Specific Menu Right Before/Next The wp_nav_menu Function?

I am trying to add custom links next/before my WP built in menu, specifically for main_menu . I have placed this in my functions.php and give my (li)’s in nav-menu-after.php and also the before file, but it’s not working.

add_filter('wp_nav_menu_items',do_wp_nav_menu_items);
function do_wp_nav_menu_items($menu, $args=array()) {
        if( file_exists( TEMPLATEPATH . '/nav-menu-before.php' ) && $args->theme_location == 'main_menu' ) {
                ob_start();
                @include TEMPLATEPATH . '/nav-menu-before.php';
                $nav_menu_before = ob_get_clean();
        }
        if( file_exists( TEMPLATEPATH . '/nav-menu-after.php'  ) && $args->theme_location == 'main_menu' ) {
                ob_start();
                @include TEMPLATEPATH . '/nav-menu-after.php';
                $nav_menu_after = ob_get_clean();
        }
        return $nav_menu_before . $menu . $nav_menu_after;
}

If I delete this part

Read More
&& $args->theme_location == 'main_menu' 

It’s working well but the custom static links appear in the whole menu I have. Not only just main_menu.

I am new to coding. Your suggestion will really be appreciated.
Thanks!

Related posts

Leave a Reply