2

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?

1

3 Answers 3

2

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';
}
Sign up to request clarification or add additional context in comments.

1 Comment

I used this and it wouldn't work from the separate php file, I had to keep the code in the main php file for it to work but thanks.
0

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.
}

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.