Fix “You do not have sufficient permissions to access this page”

In WordPress, you can add pages to the admin backend by using the functions add_menu_page() or add_options_page(). If you use these functions, you may run in an error, that you get:

You do not have sufficient permissions to access this page

Even if you are a Super Administrator. What went wrong?

Both functions allow to specify the required capability to view this page. A typical error is to use an too early hook to add the desired page. An example:

add_action('admin_init', function() {
    add_menu_page('My Page', 'My Page', 'manage_options', 'my-page', 'render_my_page');
});

This code will lead to the “You do not have sufficient permissions to access this page” error. Why? You hooked in too early. admin_init is too early, you should use admin_menu instead:

add_action('admin_menu', function() {
    add_menu_page('My Page', 'My Page', 'manage_options', 'my-page', 'render_my_page');
});

Now, your problem should be solved and the error should be gone.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top