简体   繁体   中英

Adding widget to Header.php file doesn't show in the home page?

i am working on a simple WordPress blog and i am trying to display a widget that appears in every page in the website .. i have followed the dynamic sidebar widget approach, but the problem ,

here is the Function.php file

 function wpb_widgets_init() { register_sidebar( array( 'name' => 'Custom Header Widget', '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' ); 

and my header.php file

 <?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; ?> 

and this works fine only in any single post .

but in the home page/or any template file nothing shows !!! Any ideas ?

You can try this structure and make sure your sidebar active

此链接现在点击

我已经弄清楚我必须为我的新sideBar创建一个名为sidebar-.php的模板文件,并使用get_sidebar(id)方法将其命名为Voilet,它适用于所有模板...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM