how to add submenu item under parent menu item with code


Well, here is my problem
suppose i have a menu like this generated by wp_nav_menu()

test- test1, test2

test is my custom post type

so what i want to do is if a user/admin publish posts a test post type i want it to automatically add in under test as test3.Forget about the publish_test hook i have done some research and i am ready to go with the code as follows in my functions.php

function auto_add_service_as_menu() {
    echo 'ok';exit;

function auto_remove_service_from_menu() {
    echo 'ok';exit;
add_action( 'publish_test', 'auto_add_service_as_menu' );
add_action( 'trash_test', 'auto_remove_service_from_menu' );

now what i want to do is add test3 which will be new test(cpt) post and its title and link should be automatically added to test menu.
Note: I don’t want anything to add or remove in admin dashboard or admin menu only to the user(wp_nav_menu).
So any help would be helpful.Thanks in advance

ugene 7 months 0 Answers 90 views 0

Leave an answer