TODO: To change the header's content go to Dr.Explain menu Options : Project Settings : HTML (CHM) Export : Setup HTML Template and Layout
×
Menu
Index

Tùy chỉnh Sidebar

 
* Sửa tham số sidebar:
Tất cả sidebars đã đăng ký được lưu ở biến $wp_registered_sidebars;
global $wp_registered_sidebars;
 
Nếu bạn in biến toàn cục này sẽ thấy có chứa giá trị là các tham số các sidebars:
Array
(
    [sidebar-1] => Array
        (
            [name] => Sidebar chính
            [id] => sidebar
            [description] => Appears on posts and pages except the optional Front Page template, which has its own widgets
            [class] =>
            [before_widget] => <div id="%1$s" class="box silver %2$s">
            [after_widget] => </div></div>
            [before_title] => <h3 class="header %1$s">
            [after_title] => </h3><div id="%1$s">
        )
 
 
Bạn có thể dễ dàng sửa lại tham số sidebars ở biến này trong hook init, trước khi wordpress mang đi sử dụng:
add_action('init','myinit');
function myinit(){
       global $wp_registered_sidebars;
       $wp_registered_sidebars['sidebar-1']['before_widget']='<aside id="%1$s" class="box silver %2$s">';
       $wp_registered_sidebars['sidebar-1']['after_widget'] = '</aside>';
}
 
* Tạo lại sidebar, xóa sidebar cũ và đăng ký mới:
Bạn có thể xóa sidebar cũ và đăng ký mới với hook 'widgets_init'.
function replace_sidebar_headers(){
     //remove the default sidebars from the parent theme
     unregister_sidebar('normal_sidebar');
     //add the sidebar back in modified
     register_sidebar(array(
          'name' => __('Sidebar'),
          'id' => 'normal_sidebar',
          'before_widget' => '<li id="%1$s" class="widget %2$s">',
          'after_widget' => '</li>',
          'before_title' => '<h3 class="widget-title">',
          'after_title' => '</h3>'
     ));
}
add_action('widgets_init', 'replace_sidebar_headers', 11);
 
 
Made with help of Dr.Explain

Unregistered version