I'd like to create a new page in the wp-admin panel. I know I should use the add_menu_page()
function for that and I understand how it works.
I'm new to WP development, and would just like to know in which file I should put this function. The doc does not answer to my question, or I don't understand it.
I don't know if it's possible but I'd like this page to be part of neither the plugins nor the themes.
Thanks for your help
I'd like to create a new page in the wp-admin panel. I know I should use the add_menu_page()
function for that and I understand how it works.
I'm new to WP development, and would just like to know in which file I should put this function. The doc does not answer to my question, or I don't understand it.
I don't know if it's possible but I'd like this page to be part of neither the plugins nor the themes.
Thanks for your help
As long as it gets registered before the admin_menu
hook happens, it doesn't matter what file you put it in. The important part is what hook you call your function on. For simplicity sake you could put it in a themes functions.php
. If you want things to look a bit cleaner then put it in a php file named admin-menu.php
(or whatever explanatory name you want) and require_once
that file from functions.php
add_action('admin_menu', 'your_function_name');
function your_function_name() {
add_menu_page(...)// add your menu page here
}
wp-admin
orwp-includes
to build your site, it'll all get undone on the next update. Fun story: Linkedin did this on an internal site, which meant they couldn't update and didn't get security fixes. A few years later they got hacked as a result and were fined millions for the data breach. If you're intimidated by the idea of making a plugin don't be, it's just a PHP file with a comment at the top – Tom J Nowell ♦ Commented Feb 11, 2019 at 18:55