此方法适用于您的子主题functions.php
文件
将挂钩更改为其他位置:
//functions.php
function wpsites_register_widget() {
register_sidebar( array(
\'name\' => \'After Header Widget\',
\'id\' => \'after-header\',
\'before_widget\' => \'<div>\',
\'after_widget\' => \'</div>\',
) );
}
add_action( \'widgets_init\', \'wpsites_register_widget\' );
add_filter( \'loop_start\', \'after_header_widget\', 25 );
function after_header_widget() {
if ( is_active_sidebar( \'after-header\' ) ) {
dynamic_sidebar(\'after-header\', array(
\'before\' => \'<div class="after-header">\',
\'after\' => \'</div>\',
) );
}
}
或者你可以
call the sidebar directly in your template file.
<?php if ( is_active_sidebar( \'after-header\' ) ) : ?>
<ul id="after-header">
<?php dynamic_sidebar( \'after-header\' ); ?>
</ul>
<?php endif; ?>