Kimsea Sok
Kimsea Sok

Reputation: 149

Cannot access custom admin menu page WordPress

I've been trying to register custom admin menu using the following code

function bbtre_register_admin_page(){

   add_menu_page('Revenue Share Settings', 'Reshare', 'manage_options', 'reshare-settings', 'bbtre_admin_page_callback');

}

add_action('admin_init', 'bbtre_register_admin_page');

function bbtre_admin_page_callback(){

   echo "<h1>Hell</h1>";
}

The code is working well as I can see my custom admin menu appears on the dashboard, but when click on the menu, I found that I have no permission to access the page.

Here is the message: Sorry, you are not allowed to access this page.

I've been trying to find the solution on WordPress codes, but it deosn't help even I change the capability 'switch_themes'.

Anyone please kindly help me to solve the problem?

Note: I'm working on Wordpress 9.4 and Xampp

Upvotes: 0

Views: 1220

Answers (2)

maulik
maulik

Reputation: 1052

Here is the completed code as add_action can be on above function.

add_action( 'admin_menu', 'register_my_custom_menu_page' );
function register_my_custom_menu_page() {

//add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); // for ideal practice
add_menu_page('Revenue Share Settings', 'Reshare', 'manage_options', 'reshare-settings', 'bbtre_admin_page_callback','',''); // for your code
}

function bbtre_admin_page_callback(){
 echo "Hello";
}

Upvotes: 0

Vidya L
Vidya L

Reputation: 2314

Change the hook to add_action('admin_menu', 'bbtre_register_admin_page'); to add menu on admin dashboard

Upvotes: 3

Related Questions