只需按此步骤操作一页添加自定义侧栏
Step 1: 将此代码放入主题函数中。php文件。注册自定义侧栏和自定义add\\u操作。
function wpdocs_theme_slug_widgets_init() {
register_sidebar( array(
\'name\' => __( \'Custom Sidebar\', \'textdomain\' ),
\'id\' => \'sidebar-10\',
\'description\' => __( \'Widgets in this area will be shown on all posts and pages.\', \'textdomain\' ),
\'before_widget\' => \'<li id="%1$s" class="widget %2$s">\',
\'after_widget\' => \'</li>\',
\'before_title\' => \'<h2 class="widgettitle">\',
\'after_title\' => \'</h2>\',
) );
}
add_action( \'widgets_init\', \'wpdocs_theme_slug_widgets_init\' );
add_action( \'your_custom_hook_name\', \'your_function_name\' );
function your_function_name( $sidebar_name )
{
is_page( \'sample-page\' ) && dynamic_sidebar( \'sidebar-10\' ); // your sidebar name
remove_action( current_filter(), __FUNCTION__ );
}
Step 2: 将此代码放在显示此小部件的位置
<?php do_action( \'your_custom_hook_name\' ); ?>