在里面functions.php
编写此代码
function my_optionally_widgets()
{
$option = get_options(\'wantwidget\');
if($option == \'yes\')
{
register_widget(\'mywidget\');
/* add other widgets for registration here */
}
}
add_action(\'widgets_init\', \'my_optionally_widgets\');
function my_optionally_sidebars()
{
$option = get_options(\'wantsidebar\');
if($option == \'yes\')
{
register_sidebar($args);
/* add other sidebars for registration here */
}
}
add_action(\'init\', \'my_optionally_sidebars\');
记住这一点
Widget Areas
和
Sidebars
都是完全一样的东西。但上面的代码向您展示了如何启用和禁用小部件和侧栏,使其不会出现在仪表板中。
这就是在前端显示它们的方式:
$option = get_options(\'wantsidebar\');
if($option == \'yes\')
{
dynamic_sidebar($index);
}