我很难在我创建的主题页面上显示我的“Hello World”。这一切至少看起来是正确的(但显然不是)-我在这里遗漏了什么?
// Add Theme Options to menu
function add_theme_menu_item() {
add_theme_page("Theme Panel", "Theme Panel", "manage_options", "theme-panel", "initialize_theme_options", null, 99);
}
add_action("admin_menu", "add_theme_menu_item");
/**
* Initializes the theme options page by registering the Sections,
* Fields, and Settings.
*
* This function is registered with the \'admin_init\' hook.
*/
function initialize_theme_options() {
// First, we register a section. This is necessary since all future options must belong to one.
add_settings_section(
// ID used to identify this section and with which to register options
\'main_settings_section\',
// Title to be displayed on the administration page
\'Main Theme Options\',
// Callback used to render the description of the section
\'main_settings_callback\',
// Page
\'theme-panel\'
);
}
add_action(\'admin_init\', \'initialize_theme_options\');
// end initialize_theme_options
/* ------------------------------------------------------------------------ *
* Section Callbacks
* ------------------------------------------------------------------------ */
/**
* This function provides a simple description for the General Options page.
*
* It is called from the \'initialize_theme_options\' function by being passed as a parameter
* in the add_settings_section function.
*/
function main_settings_callback() {
echo \'Hello world.\';
}
// end main_settings_callback
SO网友:Emetrop
这是错误的:
add_theme_page("Theme Panel", "Theme Panel", "manage_options", "theme-panel", "initialize_theme_options", null, 99);
最后两个参数不应该存在。在codex中检查此功能
here.
编辑:
此外,最后一个参数(应该在那里)initialize_theme_options
也是错误的,因为它应该是对输出内容的函数的回调。比如你的main_settings_callback
作用
第二次编辑:
这不管用你可能是因为add_settings_section
传入最后一个参数的函数theme-panel
这个页面可能不存在。我说得对吗?尝试将此参数替换为,例如general
它将在主设置页面输出。