在WordPress中设置自定义小工具区域需要进行以下步骤:
function custom_widget_areas() {
register_sidebar( array(
'name' => __( 'Custom Widget Area', 'textdomain' ),
'id' => 'custom-widget-area',
'description' => __( 'Add widgets here to appear in your custom widget area.', 'textdomain' ),
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'custom_widget_areas' );
<?php if ( is_active_sidebar( 'custom-widget-area' ) ) : ?>
<div class="custom-widget-area">
<?php dynamic_sidebar( 'custom-widget-area' ); ?>
</div>
<?php endif; ?>
上述代码可以在主题的任意模板文件中添加,例如可以在sidebar.php中添加,以便在侧边栏中显示自定义小工具区域。
以上就是在WordPress上设置自定义小工具区域的步骤和示例代码。