akcjaod 2.2.0
widgets_init
Opis
Odpala się po zarejestrowaniu wbudowanych widgetów. Tutaj rejestrujesz własne obszary widgetów przez register_sidebar().
Przykład użycia
add_action( 'widgets_init', ... )php
add_action( 'widgets_init', 'wpdocs_register_sidebar' );
function wpdocs_register_sidebar() {
register_sidebar( array(
'name' => __( 'Pasek boczny', 'wpdocs' ),
'id' => 'sidebar-1',
'description' => __( 'Widgety wyświetlane z boku treści.', 'wpdocs' ),
'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', 'wpdocs_register_sidebar' );
function wpdocs_register_sidebar() {
register_sidebar( array(
'name' => __( 'Pasek boczny', 'wpdocs' ),
'id' => 'sidebar-1',
'description' => __( 'Widgety wyświetlane z boku treści.', 'wpdocs' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}Wywołanie
Rejestracja callbackaphp
// rejestracja funkcji zwrotnej
add_action( 'widgets_init', 'twoja_funkcja' );
function twoja_funkcja($param_1) {
// Twój kod
}
// rejestracja funkcji zwrotnej
add_action( 'widgets_init', 'twoja_funkcja' );
function twoja_funkcja($param_1) {
// Twój kod
}