Wordpress: Register Sidebar


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //REGISTER SIDEBAR
  2. register_sidebar( array(
  3. 'name' => 'Footer Area One',
  4. 'id' => 'sidebar-3',
  5. 'description' => 'An optional widget area for your site footer',
  6. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  7. 'after_widget' => "</aside>",
  8. 'before_title' => '<h3 class="widget-title">',
  9. 'after_title' => '</h3>',
  10. ) );
  11.  
  12. register_sidebar( array(
  13. 'name' => 'Footer Area Two',
  14. 'id' => 'sidebar-4',
  15. 'description' => 'An optional widget area for your site footer',
  16. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  17. 'after_widget' => "</aside>",
  18. 'before_title' => '<h3 class="widget-title">',
  19. 'after_title' => '</h3>',
  20. ) );
  21.  
  22. register_sidebar( array(
  23. 'name' => 'Footer Area Three',
  24. 'id' => 'sidebar-5',
  25. 'description' => 'An optional widget area for your site footer',
  26. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  27. 'after_widget' => "</aside>",
  28. 'before_title' => '<h3 class="widget-title">',
  29. 'after_title' => '</h3>',
  30. ) );
  31.  
  32.  
  33. //COUND THE NUMBER OF FOOTER SIDEBARS TO ENABLE DYNAMIC CLASSES FOR THE FOOTER
  34. function custom_footer_sidebar_class() {
  35.  
  36. $count = 0;
  37. if ( is_active_sidebar( 'sidebar-3' ) ) $count++;
  38. if ( is_active_sidebar( 'sidebar-4' ) ) $count++;
  39. if ( is_active_sidebar( 'sidebar-5' ) ) $count++;
  40.  
  41. $class = '';
  42. switch ( $count ) {
  43. case '1': $class = 'one'; break;
  44. case '2': $class = 'two'; break;
  45. case '3': $class = 'three'; break;
  46. }
  47.  
  48. if ( $class ) echo 'class="' . $class . '"';
  49. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.