skip to Main Content

I want to add a menu to the wordpress admin with an ID, that is, without a link. I want to add it to activate a modal/popup that I will add. I can place a floating button, but I want to have it all more organized.

Here’s how to create the menu: https://developer.wordpress.org/reference/functions/add_menu_page/

What I don’t know is how to make it just have an icon, name, and ID, with no redirect link.

3

Answers


  1. You can hook into the global $menu like so

    add_action( 'admin_menu' , 'admin_menu_custom_menu' );
    function admin_menu_custom_menu() {
        global $menu;
        $menu[20] = array( 'Menu item name', 'manage_options' , 'http://example.com', '', 'classname', '', 'dashicons name or link to image' ); 
    }
    

    Just make sure that there $menu[20] doesn’t exist or it will overwrite it.

    Login or Signup to reply.
  2. Check this out buddy 🙂

    add_action('admin_menu', 'register_sample_page');
    
    function register_sample_page() {
        add_menu_page( "BELO", "BELO", "manage_options", "belo_main",  false); 
        add_submenu_page( 'belo_main', 'sample 1', 'sample 1', 'manage_options', 
           'belo_main', 'anothersample_callback' ); 
        add_submenu_page( 'belo_main', 'sample 2', 'sample 2', 'manage_options',
            'sample-menu', 'sample_callback' );  
        
    }
    
    function belo_filter( $submenu_file ) {
    
        global $plugin_page;
    
        $hidden_submenus = array(
            'sample-menu' => true,
        );
    
          
        // Hide the submenu item.
        foreach ( $hidden_submenus as $submenu => $unused ) {
            remove_submenu_page( 'belo_main', $submenu );
        }
    
        return $submenu_file;
    }
    add_filter( 'submenu_file', 'belo_filter' );
    
    Login or Signup to reply.
  3. Another simpler solution can be:

    add_action('admin_menu', 'register_sample_page');
    
    function register_sample_page() {
        
        add_menu_page( "BELO", "BELO", "manage_options", "belo_main",  false); 
        
        add_submenu_page( 'belo_main', 'sample 1', 'sample 1', 'manage_options', 
           'belo_main', 'anothersample_callback' ); 
        
        add_submenu_page( 'belo_main', 'sample 2', 'sample 2', 'manage_options',
            'sample-menu', 'sample_callback' );  
        
    }
    
    function belo_filter( ) {
         
        remove_submenu_page( 'belo_main', 'sample-menu');
    }
    
    add_action( 'admin_head', 'belo_filter' );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search