Advertisement
pixeline

Wordpress Custom Sidebar UI Improvement

Oct 30th, 2011
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. // STEP 1. Add a admin-sidebar-selector.js file inside your "js" theme folder
  2.  
  3. jQuery(document).ready(function($){
  4.  
  5. // fetch all sidebars
  6. var allNames='';
  7. $('#widgets-right .sidebar-name h3').each(function(){
  8. allNames+= '<option value="'+$(this).text()+'">'+$(this).text()+'</option>';
  9. });
  10.  
  11. // hide them all but the first one
  12. $('#widgets-right .widgets-holder-wrap').hide().filter(':eq(0)').show();
  13.  
  14. $('#widgets-right').prepend('<div id="sidebar_selector_menu" style="padding:1em;border:1px solid #CCC;margin:1em 0;"><label for="sidebar_selector">Select the sidebar you want to modify:</label><select id="sidebar_selector" name="sidebar_selector">'+allNames+'</select></div');
  15. $('#sidebar_selector').change(function(){
  16. var val = $(this).val();
  17. $('#widgets-right .widgets-holder-wrap').hide();
  18. var result = $('#widgets-right .widgets-holder-wrap h3:contains("'+val+'")');
  19. var parent = result.eq(0).parents('.widgets-holder-wrap:first').show();
  20. });
  21. });
  22.  
  23.  
  24.  
  25. // STEP 2. Put this In your Theme functions.php:
  26.  
  27. function sidebar_selector_dropdown_menu() {
  28. wp_enqueue_script('sidebar-selector-js', get_stylesheet_directory_uri().'/js/admin-sidebar-selector.js', array('jquery'));
  29. }
  30. add_action('admin_print_scripts-widgets.php', 'sidebar_selector_dropdown_menu');
  31.  
  32.  
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement