小工具未在Wordpress中显示

时间:2017-10-03 10:31:27

标签: php html wordpress plugins widget

我的Wordpress小部件中有一个探测器。我用HTML创建了一个Wordpress模板。我想在我的关于我们页面上添加此小部件,但不显示小部件。

这是我在function wpb_widgets_init() { register_sidebar( array( 'name' => 'Custom Header Widget Area', 'id' => 'custom-header-widget', 'before_widget' => '<div class="chw-widget">', 'after_widget' => '</div>', 'before_title' => '<h2 class="chw-title">', 'after_title' => '</h2>', ) ); } add_action( 'widgets_init', 'wpb_widgets_init' );

中的代码
page-about.php

此代码是我的主题<?php if ( is_active_sidebar( 'custom-header-widget' ) ) : ?> <div id="header-widget-area" class="chw-widget-area widget-area" role="complementary"> <?php dynamic_sidebar( 'custom-header-widget' ); ?> </div> <?php endif; ?>

[0-3][0-9][0-1][1-9]\d{2}[-\s]\d{4}?[^0-9]*|[0-3][0-9][0-1][1-9]\d{2}\d{4}

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

function.php

中添加以下代码
function wpb_widgets_init() {

register_sidebar( array(
    'name'          => 'Custom Header Widget Area',
    'id'            => 'custom-header-widget',
    'before_widget' => '<div class="chw-widget">',
    'after_widget'  => '</div>',
    'before_title'  => '<h2 class="chw-title">',
    'after_title'   => '</h2>',
   ) );
}

add_action( 'widgets_init', 'wpb_widgets_init' );

并在 page-about.php

中添加此代码
<?php
 if ( is_active_sidebar( 'custom-header-widget' ) ) : ?>
    <div id="header-widget-area" class="chw-widget-area widget-area" role="complementary">
    <?php dynamic_sidebar( 'custom-header-widget' ); ?>
    </div>

<?php endif; ?>