我很难让我的“Hello”显示在我创建的主题页面上。这一切至少看起来都是正确的(但显然不是)--我在这里错过了什么?
// 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发布于 2015-08-20 22:40:45
这是错误的:
add_theme_page("Theme Panel", "Theme Panel", "manage_options", "theme-panel", "initialize_theme_options", null, 99);最后两个参数不应该在那里。请在代码库这里中检查此函数。
编辑:
更重要的是,最后一个参数(应该在那里) initialize_theme_options也是错误的,因为它应该是对输出内容的函数的回调。例如,您的main_settings_callback函数。
第二次编辑:
它不起作用,可能是因为在add_settings_section函数的调用中传递了最后一个参数theme-panel,并且这个页面可能不存在。我说的对吗?例如,尝试用general替换这个参数,它将在主设置页面输出。
发布于 2015-08-20 23:45:26
好的,我知道了。
https://codex.wordpress.org/Function_参考/做_设置_章节
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'
);
do_settings_sections('theme-panel');
} https://wordpress.stackexchange.com/questions/199244
复制相似问题