01/10/2018, 17:31
Cách tạo Widget Areas
Đoạn code bên dưới minh họa việc thêm 2 widget areas có tên: First Widget Area và Second Widget Area vào sidebar. Bạn mở tập tin functions.php có đường dẫn: wp-content hemes{tên-theme-của-bạn}functions.php. Thêm vào đoạn code bên dưới. function my_widgets_init() { register_sidebar( ...
Đoạn code bên dưới minh họa việc thêm 2 widget areas có tên: First Widget Area và Second Widget Area vào sidebar. Bạn mở tập tin functions.php có đường dẫn: wp-content hemes{tên-theme-của-bạn}functions.php. Thêm vào đoạn code bên dưới.
function my_widgets_init() {
register_sidebar( array(
'name' => 'First Widget Area',
'id' => 'first-widget-area',
'description' => __( 'The first widget area'),
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => "</li>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => 'Second Widget Area',
'id' => 'second-widget',
'description' => __( 'The second widget area'),
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => "</li>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
// Add the widget areas
add_action( 'init', 'my_widgets_init' );
Nhấn phím Ctrl + S để lưu lại tập tin functions.php
Bạn vào phía admin: AppearanceWidget để để xem 2 widget areas vừa tạo ở trên.
Góc Kinh Nghiệm chúc các bạn thành công! 