0

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

2
  • 1
    It HAS to be in either a plugin or a theme. Otherwise it is either (a) not included, therefore not going to work, or (b) part of WordPress core, which you should not modify as it will be overwritten every time WP is upgraded.
    – tmdesigned
    Commented Feb 11, 2019 at 17:32
  • Modifying WordPress itself is a massive no no, never make changes in wp-admin or wp-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

1 Answer 1

0

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

}
3
  • 1
    It has to be registered before the admin_menu action is fired though, so I don't know if I would say it doesn't matter as long as it is required.
    – tmdesigned
    Commented Feb 11, 2019 at 17:34
  • Good point. Edited for clarification.
    – mrben522
    Commented Feb 11, 2019 at 18:33
  • thanks a lot for your answers! really helped me out
    – Melinsuna
    Commented Feb 12, 2019 at 8:04

Your Answer

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

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