扩展Jan的答案,我发现strpos()
而不是strncmp()
用于检查小部件名称(更快..)
下面,您将发现一个类似的功能(正在运行和测试),它将使您获得相同的结果:
add_filter( \'sidebars_widgets\', \'hide_widgets\' );
function hide_widgets( $excluded_widgets )
{
if ( is_page() /* Or whatever */ ) {
//set the id in \'sidebar-id\' to your needs
foreach ( $excluded_widgets[\'sidebar-id\'] as $i => $inst) {
//in this example we\'ll check if the id for the rss widgets exists.(change it to suit your needs)
$pos = strpos($inst, \'rss\');
if($pos !== false)
{
//unsetting the id will remove the widget
unset($excluded_widgets[\'sidebar-id\'][$i]);
}
}
}
return $sidebars_widgets;
}