I am trying to creat an custom option page but I ham getting error on setting the add menu page() function. I need to use the FILE as the $menu_slug 4th parameter of the function

  add_menu_page('Item Display','Item Display','administrator', '__FILE__', function(){  });

but I am getting this error: You do not have sufficient permissions to access this page.

enter image description here


Your code should work (not how you expect but it should work), and probably the error was in something that you didn't post.


__FILE__ is a constant: you don't have to use quotes when write it.

Remove them like so:

add_menu_page('Item Display','Item Display','administrator', __FILE__, function(){  });

If you use the quotes, '__FILE__' became a string and so with your code the menu page should be shown when you visit an url similar to:


If you remove the quotes as I've done above, your page will respond to an url similar to:


Also note that when you pass a function as 5th param for add_menu_page (just like you do) that function is used for render the page content whatever you use for $menu_slug (4th) param.

If you want use a file to render the page content, this file must be in the WP plugin folder and you have to pass the url of this file relative to the WP plugin folder. E.G.:

add_menu_page('Item Display','Item Display','administrator', 'myplugin/myplugin-admin.php', '');

Using the code above, the content of the admin page is rendered by a file named myplugin-admin.php located in the folder myplugin under the WP plugin folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.