我试图在我的Genesis子主题中为WordPress注册一个新的小部件区域。代码似乎无法正常工作并导致我的网站崩溃。谁能告诉我我在这里做错了什么?我试图将它放在所有页面上的内容之上。这是我的代码:
genesis_register_sidebar( array(
'id' => ‘above_content’,
'name' => __( ‘Above Content’, 'domain' ),
'description' => __( ‘Above the content’, 'domain' ),
));
add_action( 'genesis_before_loop’, ‘above_content’ );
function your_widget() {
if ( is_active_sidebar(‘above_content’) ) {
genesis_widget_area( ‘above_content’, array(
'before' => '<div class=“above_content widget-area">',
'after' => '</div>',
));
}
}
答案 0 :(得分:1)
两件事:
'
,而不是引号‘
genesis_register_sidebar( array(
'id' => 'above_content',
'name' => __( 'Above Content', 'domain' ),
'description' => __( 'Above the content', 'domain' ),
) );
add_action( 'genesis_before_loop', 'your_widget' );
function your_widget() {
if ( is_active_sidebar('above_content') ) {
genesis_widget_area( 'above_content', array(
'before' => '<div class="above_content widget-area">',
'after' => '</div>',
) );
}
}
如果要注册另一个小部件,只需注册一个新的侧边栏(具有唯一ID),并将新逻辑添加到新的回调函数(或将其添加到your_widget()
)。添加此附加小部件的位置取决于您的特定用例。