Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

My theme has a custom menu assignment...

function my_register_my_menus() {
  register_nav_menus(
    array('header-menu' => __( 'Custom Header Menu' ) )
  );
}

...and I'm creating an "installer" type plugin that, upon activation, I would like to hook into this custom menu and assign some pages to it as if they had been created manually.

However, the menu API is pretty new and to date, I've been unable to find any examples of how to do this.

I'm hoping someone here can give me some direction, examples or info on how to do it.

Thanks in advance :-)

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You can use wp_nav_menu_{$menu->slug}_items hook and add you link with a callback function, for example if your menu slug is header-menu then something like this:

add_filter('wp_nav_menu_header-menu_items', 'add_my_extra_links',10,2);
function add_my_extra_links($items, $args) {
  $newitems = '<li><a title="Test Link" href="http://google.com">Google</a></li>';
  $newitems .= '<li><a title="Test Link" href="http://yahoo.com">Yahoo</a></li>';
  $newitems .= '<li><a title="Test Link" href="http://bing.com">Bing</a></li>';
  $newitems .= $items;
  return $newitems;
}

Update

I guess you would need to call wp_save_nav_menu_items which is the function used to save the menu items to the database.

share|improve this answer
    
I can't tell you how appreciative I am to see ANY signs of life on this question. One thing though, since this is a filter, I'm not sure its what I'm looking for. I need to be able to create a menu via script once, during plugin activation so that its just as if I created it manually on the site, and it persists without a runtime filter. Does this make sense? –  Scott B Mar 26 '11 at 22:44
    
I've updated my question to clarify a bit. I can see that it was not clear on the aspect of all of this being done on plugin activation (once and done). –  Scott B Mar 26 '11 at 22:52
    
@Scott: i updated my answer in short because its really late here and I'm half a sleep, but it should get you somewhere. –  Bainternet Mar 26 '11 at 23:15
    
+1 for your help thus far. You gave me 100% more than I had before you answered :-) –  Scott B Mar 27 '11 at 0:25
    
Thanks! –  Scott B Apr 6 '11 at 16:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.