• Hello,
    I can’t find any solution my problem,i am using this add_action(‘save_post’,’my_function’)but no result,and i want to add item to custom menu (with link domain/#page-title) directly after saving page and rename the link after any change on the page title also removing item from the menu after deleting page.
    thank you so much

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter oudrib

    (@oudrib)

    Hi @spgandhi,
    Thank you for your fast response i just started coding with this :
    if ( ! function_exists(‘regenerate_menu’)){
    function regenerate_menu( $post ) {

    remove_action(‘edit_post’, ‘regenerate_menu’);
    remove_action(‘save_post’, ‘regenerate_menu’);
    remove_action(‘publish_post’, ‘regenerate_menu’);
    remove_action(‘edit_page_form’, ‘regenerate_menu’);
    add_action(‘trash_post’, ‘regenerate_menu’);

    $list_pages = wp_list_pages($args);

    foreach ($list_pages as $key => $value) {
    $hash_link = mb_convert_encoding(str_replace(‘ ‘, ”, $post->post_title), ‘EUC-JP’, ‘auto’);
    }

    if( home_url( ‘/#’. $hash_link) == $link->url ){
    wp_update_nav_menu_item($themenu->term_id, $link->ID, array(
    ‘menu-item-title’ => __( get_the_title() ),
    ‘menu-item-url’ => home_url( ‘/#’. $hash_link ),
    ‘menu-item-status’ => ‘publish’));
    $flag = $key;
    }

    }
    add_action(‘edit_post’, ‘regenerate_menu’);
    add_action(‘save_post’, ‘regenerate_menu’);
    add_action(‘publish_post’, ‘regenerate_menu’);
    add_action(‘edit_page_form’, ‘regenerate_menu’);
    add_action(‘trash_post’, ‘regenerate_menu’);
    }

    Moderator bcworkz

    (@bcworkz)

    Why do you want a custom menu? The WP nav menu does everything you describe, why not use that?

    Thread Starter oudrib

    (@oudrib)

    Hi @bcworkz,
    thank you for your response, i want to create custom items in the menu (home_url/#about) and list all pages in section with id=about … and wordpress doesn’t do this

    Moderator bcworkz

    (@bcworkz)

    The WP nav menu is endlessly customizable. The ‘wp_nav_menu’ filter passes to your callback the entire menu’s HTML for you to alter as you please just before it is output to the browser. For complete control, write (or customize the default) a walker function to process each menu item in turn.

    Thread Starter oudrib

    (@oudrib)

    Thank you @bcworkz i will try this 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Run function after save page add_action('save_post','my_function') doesn't’ is closed to new replies.