'Adding the custom page with add_menu_page function on Wordpress

I am using the add_menu_page function on WordPress; this is the code;

function my_admin_menu() {
    add_menu_page( 'My Top Level Menu Example', 'Top Level Menu', 
       'manage_options', 'example.php', 'myplguin_admin_page', 'dashicons-tickets', 6 );
}

example.php

function display_text() {
    echo 'Welcome to my page';
}

I get the menu in the dashboard, but the issue has content on the page. I can click the top-level option page from the dashboard, but once I do that, I get an empty page where it should say 'Welcome To My page'. Any ideas on how to get my content to show?



Solution 1:[1]

You were using a wrong function name that is why it was showing a blank page.

function my_admin_menu() {
    add_menu_page( 'My Top Level Menu Example', 'Top Level Menu', 'manage_options', 'example.php', 'myplguin_admin_page', 'dashicons-tickets', 6  );
}

function myplguin_admin_page(){
    echo 'Welcome to admin page';
}

Solution 2:[2]

You can try this code, because i use this and work

add_menu_page(
    'Import Resi', // Page Title
    'Import Resi', // Menu Title
    'manage_options', // Capabiliy
    'import_php/index.php', // Menu_slug
    '', // function
    '', // icon_url
    6   // position
);
add_menu_page(
    'Admin Cek', // Page Title
    'Admin Cek', // Menu Title
    'manage_options', // Capabiliy
    'admin_cek/index.php', // Menu_slug
    '', // function
    '', // icon_url
    7   // position
);

Solution 3:[3]

you need to use the correct function name and a more appropriate identifier than example.php. you can require your file from the called function

function my_admin_menu() {
   add_menu_page( 'My Top Level Menu Example', 'Top Level Menu', 'manage_options', 'example', 'display_text', 'need a uri to your image here!!', 6  );
}


function display_text(){
    require_once 'pathtofile.php'; //--> make sure you read up on paths and require to find your file.
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nic3500
Solution 2 Dimas Anugerah
Solution 3 David