Rajouter une zone de widgets:
Il nous faut créer un enfant de function.php, dans notre thème enfant.
Dedans coller une partie du code de son parent:
<?php
function twentysixteen_widgets_init() {
register_sidebar( array(
‘name’ => __( ‘Sidebar’, ‘twentysixteen’ ),
‘id’ => ‘sidebar-1’,
‘description’ => __( ‘Add widgets here to appear in your sidebar.’, ‘twentysixteen’ ),
‘before_widget’ => ‘<section id= »%1$s » class= »widget %2$s »>’,
‘after_widget’ => ‘</section>’,
‘before_title’ => ‘<h2 class= »widget-title »>’,
‘after_title’ => ‘</h2>’,
) );
register_sidebar( array(
‘name’ => __( ‘Content Bottom 1’, ‘twentysixteen’ ),
‘id’ => ‘sidebar-2’,
‘description’ => __( ‘Appears at the bottom of the content on posts and pages.’, ‘twentysixteen’ ),
‘before_widget’ => ‘<section id= »%1$s » class= »widget %2$s »>’,
‘after_widget’ => ‘</section>’,
‘before_title’ => ‘<h2 class= »widget-title »>’,
‘after_title’ => ‘</h2>’,
) );
register_sidebar( array(
‘name’ => __( ‘Content Bottom 2’, ‘twentysixteen’ ),
‘id’ => ‘sidebar-3’,
‘description’ => __( ‘Appears at the bottom of the content on posts and pages.’, ‘twentysixteen’ ),
‘before_widget’ => ‘<section id= »%1$s » class= »widget %2$s »>’,
‘after_widget’ => ‘</section>’,
‘before_title’ => ‘<h2 class= »widget-title »>’,
‘after_title’ => ‘</h2>’,
) );
}
add_action( ‘widgets_init’, ‘twentysixteen_widgets_init’ );
Puis faire les modification:
<?php
function enfant_twentysixteen_widgets_init() {
register_sidebar( array(
‘name’ => ‘Zone de widgets superieur 1’ ,
‘id’ => ‘sidebar-5’,
‘description’ => ‘Zone de widget sous l\’entete.’ ,
‘before_widget’ => ‘<section id= »%1$s » class= »widget %2$s »>’,
‘after_widget’ => ‘</section>’,
‘before_title’ => ‘<h2 class= »widget-title »>’,
‘after_title’ => ‘</h2>’,
) );
}
add_action( ‘widgets_init’, ‘enfant_twentysixteen_widgets_init’ );
Sur notre page header(enfant) ou nous voulons rajouter notre sidebar il nous suffit de coller:
<div class= »zone-widgets-sous-entete »>
<?php dynamic_sidebar( ‘sidebar-5’ ); ?>
</div>
Pour plusieurs sidebars, répéter la manœuvre entre les accolades.
ex:
<?php
function enfant_twentysixteen_widgets_init() {
register_sidebar( array(
‘name’ => ‘Zone de widgets superieur de l\’entete’,
‘id’ => ‘sidebar-5’,
‘description’ => ‘Zone de widget sur l\’entete.’ ,
‘before_widget’ => ‘<section id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ‘</section>’,
‘before_title’ => ‘<h2 class=”widget-title”>’,
‘after_title’ => ‘</h2>’,
) );
register_sidebar( array(
‘name’ => ‘Zone de widgets inferieur de l\’entete’,
‘id’ => ‘sidebar-6’,
‘description’ => ‘Zone de widget sous l\’entete.’ ,
‘before_widget’ => ‘<section id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ‘</section>’,
‘before_title’ => ‘<h2 class=”widget-title”>’,
‘after_title’ => ‘</h2>’,
) );
register_sidebar( array(
‘name’ => ‘Zone de widget sous l\’entete.’,
‘id’ => ‘sidebar-acceuil’,
‘description’ => ‘Zone de widgets au dessus de l\’entete de la page d\’acceuil’ ,
‘before_widget’ => ‘<section id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ‘</section>’,
‘before_title’ => ‘<h2 class=”widget-title”>’,
‘after_title’ => ‘</h2>’,
) );
}
add_action( ‘widgets_init’, ‘enfant_twentysixteen_widgets_init’ );
Un lien utile: