Tuesday, May 7, 2013

Wordpress Menu add item through Code

If you want to add menu item through your code  for your wordpress blog. Just follow the steps to get it. Wordpress menu need theme support and 'nav-menu' activation .

 here is simple code help you to add a contact form to the menu.


function add_menu_content() {
    $wordpress = array(
'post_title' => 'Contact',
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => '1',
'post_type' => 'nav_menu_item',
'meta_key' => '_menu_item_menu_item_parent' 

);
$post_id = wp_insert_post($wordpress);
add_post_meta($post_id, '_menu_item_url', 'http://localhost/kvp/contact/');
add_post_meta($post_id, '_menu_item_type', 'custom');
wp_set_post_terms( $post_id, 'summa', 'nav_menu');
}

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete