principemestizo3
principemestizo3

Reputation: 191

Add an admin menu to wordpress without link

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.

Upvotes: 1

Views: 1337

Answers (3)

Belo Kiganda Cylas
Belo Kiganda Cylas

Reputation: 31

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' );

Upvotes: 0

Belo Kiganda Cylas
Belo Kiganda Cylas

Reputation: 31

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' );

Upvotes: 3

Moshe Gross
Moshe Gross

Reputation: 1395

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.

Upvotes: 1

Related Questions