WordPress.org

Ready to get started?Download WordPress

Forums

Create my own menu (plugin) (12 posts)

  1. Boulli
    Member
    Posted 1 year ago #

    Hi,
    I would like to have my own menu on wp-admin/nav-menus.php (left part),
    who will produce my own content.
    How can I do this? Everything I found is about themes.

    Thanks

  2. esmi
    Forum Moderator
    Posted 1 year ago #

  3. Boulli
    Member
    Posted 1 year ago #

    Hi,
    I'm not a user but a developer...
    I want to create my own custom menu.
    That page is about using the existing custom menus.

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    Sorry - when you said "Everything I found is about themes", I assumed you were not developing your own theme. See Navigation_Menus.

  5. Boulli
    Member
    Posted 1 year ago #

    Tanks but I already saw this page and it seems to be only to add the menu on the themes. Not to create one with a plugin.

    Maybe I explain it wrong, so I made a picture:

    I would like to have my own menu like here.

    So that when added it, it gives that output

    My plugin will output some html (forms, tables, ...).
    So it will work on any theme.

  6. Andrew Bartel
    Member
    Posted 1 year ago #

    The answer lies within the link esmi posted. Read the documentation on the functions.

  7. Boulli
    Member
    Posted 1 year ago #

    Sorry but the answer is not in the link. :/
    I don't want to change anything to my theme.
    Actually i'm using the Twenty Twelve theme and I don't want to change it.

    A dirty way to do what I want, would be to
    1. create a page with a shortcode
    2. add a menu with that page as content
    But it's definitely not an intuitive way for the user.

    Maybe I can create and add that automatically when my plugin is loaded.
    But what if the user edit or remove the page.
    Or if he want to remove the menu just for some days.

    There should be a direct way for doing this but I could not find it.

    @esmi: could you move back this topic on the "hack" place, please.
    It would be a better place.

  8. Boulli
    Member
    Posted 1 year ago #

    In fact, I'm looking for an equivalent of wp_widget for menus who will work like this:

    class My_Menu extends WP_Menu {
    	public function __construct() {
    		// menu actual processes
    	}
     	public function form( $instance ) {
    		// outputs options form on admin: nav-menus.php, left
    	}
    	public function update( $new_instance, $old_instance ) {
    		// processes menu options to be saved
    	}
    	public function menu( $args, $instance ) {
    		// outputs the content of the menu
    	}
    }
    register_menu( 'My_Menu' );

    This would be perfect.
    But I couldn't find something like this :(

  9. Andrew Bartel
    Member
    Posted 1 year ago #

    Yes, it is. register_nav_menu will add a menu you in the location you showed in your first photo, wp_nav_menu() will display the menu when you call it in your template files.

    RTFM dude.

  10. Boulli
    Member
    Posted 1 year ago #

    I read it.

    How is register_nav_menu( ); suppose to work as on my first photo: there is no way to add a function like:

    register_nav_menu(..., 'my_form');
    
    function my_form() {
            echo 'Option1: <input type="text" name="option">'
    }

    I don't get how it's working. And they don't speak about plugins in this link.

  11. Andrew Bartel
    Member
    Posted 1 year ago #

    Indeed, you can create a menu programmatically.

    Menu items are stored in the wp_posts table with a post_type of nav_menu_item.

    Create a menu that has some of the functionality that you want and see how it's stored in the database. Then, figure out a way to add it in automagically. One way would be to use wp_insert_post(). Then, you can build around that functionality in your plugin.

  12. Boulli
    Member
    Posted 1 year ago #

    I excepted an easier way.
    But thanks I understand how it's working now.

Topic Closed

This topic has been closed to new replies.

About this Topic