Last active
March 30, 2018 19:09
-
-
Save 1naveengiri/9b6a72c4b39224f8a671f5c605554fc5 to your computer and use it in GitHub Desktop.
How to add page/post as menu Item programmatically in WordPress?
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
<?php | |
/** | |
* To add a page/post in WordPress menu | |
*/ | |
$menu_id = 4; //menu ID. | |
$_post_id = 5; // post/page ID. | |
// note here $menu_item_db_id is already added menu item ID, if it will be 0 new menu will be added otherwise we can edit previous menu with code. | |
$menu_response_data = wp_update_nav_menu_item( $menu_id , $menu_item_db_id=0, array( | |
'menu-item-object-id' => $_post_id, | |
'menu-item-object' => 'page', | |
'menu-item-title' => wp_strip_all_tags( __( 'My Page', 'awesome-support' ) ), | |
'menu-item-status' => 'publish', | |
'menu-item-type' => 'post_type' | |
) | |
); | |
To read more please visit link below. | |
http://buddydevelopers.com/how-to-add-menu-item-programmatically-in-wordpress/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment