我使用了中提供的代码this tutorial 要在仪表板中创建选项菜单,但与预期相反,我在仪表板中没有看到任何新菜单:
<?php
add_action(\'admin_menu\', \'add_global_custom_options\');
function add_global_custom_options()
{
add_options_page(\'Global Custom Options\', \'Global Custom Options\', \'manage_options\', \'functions\',\'global_custom_options\');
}
function global_custom_options()
{
?>
<div class="wrap">
<h2>Global Custom Options</h2>
<form method="post" action="options.php">
<?php wp_nonce_field(\'update-options\') ?>
<p><strong>Twitter ID:</strong><br />
<input type="text" name="twitterid" size="45" value="<?php echo get_option(\'twitterid\'); ?>" />
</p>
<p><input type="submit" name="Submit" value="Store Options" /></p>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="twitterid" />
</form>
</div>
<?php
}
我做错了什么?我在我的子主题中添加了此代码
functions.php
.
SO网友:M Ali Salim
确保您的函数、Slug和回调函数是唯一的(意味着不同于任何其他插件或默认WordPress)。还可以使用设置API保存选项http://codex.wordpress.org/Function_Reference/register_setting
<?php
add_action(\'admin_menu\', \'add_unique_custom_options\');
function add_unique_custom_options()
{
add_options_page(\'Global Custom Options\', \'Global Custom Options\', \'manage_options\', \'unique-functions\',\'unique_custom_options\');
}
function unique_custom_options()
{
?>
<div class="wrap">
<h2>Global Custom Options</h2>
<form method="post" action="options.php">
<?php wp_nonce_field(\'update-options\') ?>
<p><strong>Twitter ID:</strong><br />
<input type="text" name="twitterid" size="45" value="<?php echo get_option(\'twitterid\'); ?>" />
</p>
<p><input type="submit" name="Submit" value="Store Options" /></p>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="twitterid" />
</form>
</div>
<?php
}