WordPress和对未定义函数add_menu_page()的调用 [英] WordPress and Call to undefined function add_menu_page()
问题描述
我最近开始从事WordPress插件开发,我想添加一个菜单页面(左侧菜单中的链接).之前的SO问题和WordPress Codex都说它就像调用一样简单:
I recently got into WordPress plugin development and I would like to add a menu page (the links in the left hand side menu). Previous SO questions and the WordPress codex say that it's as simple as calling:
add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
但是,当我在插件设置文件中尝试此操作时,它告诉我该函数未定义:
However when I try this in my plugin setup file it tells me that the function is undefined:
PHP Fatal error: Call to undefined function add_menu_page()
根据文档,这似乎是一件非常简单的事情,但我完全感到困惑.任何帮助将不胜感激:)
This seems like a very simple thing to do according to the documentation but I am totally baffled. Any help would be really appreciated :)
推荐答案
我不知道您的代码看起来如何,但这就是我刚刚测试的方式及其工作方式:
I don't know how your code looks but this is how I just tested and it worked:
add_action('admin_menu', 'my_menu');
function my_menu() {
add_menu_page('My Page Title', 'My Menu Title', 'manage_options', 'my-page-slug', 'my_function');
}
function my_function() {
echo 'Hello world!';
}
在这里看看 http://codex.wordpress.org/Administration_Menus
这篇关于WordPress和对未定义函数add_menu_page()的调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!