add menu page - Add item to admin panel - wo plugin & theme

admin2025-06-03  3

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

Share Improve this question asked Feb 11, 2019 at 17:11 MelinsunaMelinsuna 1135 bronze badges 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
Add a comment  | 

1 Answer 1

Reset to default 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

}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748918086a314805.html

最新回复(0)