You can get the list of widgets in a sidebar via:
wp.customize('sidebars_widgets[sidebar-1]').get()
This is a list of the widgets’ IDs. The sidebars_widgets[sidebar-1]
is the setting ID for the sidebar. Replace sidebar-1
with the ID of your sidebar.
So to get the count just do:
wp.customize('sidebars_widgets[sidebar-1]').get().length
If you want to listen for when a widget is added or removed to a sidebar, you can bind
to the setting
to listen for changes, like this:
wp.customize( 'sidebars_widgets[sidebar-1]', function( sidebarSetting ) {
sidebarSetting.bind( function( newWidgetIds, oldWidgetIds ) {
console.info( {
added: _.difference( newWidgetIds, oldWidgetIds ),
removed: _.difference( oldWidgetIds, newWidgetIds )
} );
} )
} );
Related Posts:
- Can a widget in the Customizer be “single-use” (i.e. disabled after 1 instance has been added)?
- Changes in widget customizer not triggering ‘save and publish’
- How to refresh Theme Customizer after change color inside wpColorPicker?
- Widgets not displaying in theme customizer
- How to enable “shift-click to edit this widget” functionality on a custom widget?
- Remove the widgets tab from theme customizer
- Wp Customizer event for when a new widget has been added
- How to determine the number of widgets contained in a sidebar via customizer JS
- Sidebar not show customizer!
- Can’t see widget areas in my customizer
- Adding widgets with Featured Image via the Customizer run hundreds of queries
- Widget changes in customizer ajax error to many options?
- Color picker in widget appears twice when added via the Customizer
- WordPress Edit Button not appearing for widget in customizer
- Make single widget area top level in 4.0 Customize Panel
- Widget not appearing in customizer
- How do I enable the admin form for a custom widget that is called in a sidebar template, not to widget area?
- How to move widget area to another section in WordPress Customizer
- Force update widget customizer using js
- Add Control in Widgets Sub-Panel in Customizer
- Add Social Media icon widget to customizer
- Use customizer or sidebar for header settings?
- Using javascript on the new widget preview / customizer page
- Modifying the default search widget
- How to build widget with arrays inside arrays?
- How do I save data from submitted form from widget
- How to listen to color changes on the color picker?
- Unregistering a Sidebar in Child Theme
- Problems with the sidebar args and wp_list_bookmarks
- Ban certain widgets from certain sidebars
- How to use jQuery on widget admin page
- How could a Widget behave differently depending on sidebar
- jQuery does not work in widget backend
- iris color picker in widget – click event doesn’t fire when initially when widget is first created
- Custom widget using get_categories select menu dropdown
- Find if widget block is active
- Elegantly using JavaScript on widget admin forms
- Widget queries even when there are no sidebars?
- Multiple users editting widgets
- How to rename wordpress Widget
- How to hack recent comments default widget?
- jQuery UI inside widget on admin page
- How do I add a widget from an Android phone?
- Error gets thrown when calling require_once on widget.php
- How to activate or install the Gallery Widget?
- Custom User Field in Dashboard Widget
- Getting a div wrapped around two widgets
- How to create a widget that accepts html input?
- Widgets not adding div on before and after title
- Dynamically add content to an existing widget area
- RSS dashboard widget not showing visuals
- Simple widget causing whitescreen
- How to stop comments widget conflicting with theme comments
- How do I create a widget to embed the code for a sign up form, so that the sign up form appears on every page?
- Tabs and Category Widget
- How to change the default class for the widget title?
- How to add the same widget twice?
- How to hide widget if current category has no posts assigned to it?
- Unable to load “wpColorPicker” on theme customize page
- Undefined Variable in my widget
- Update widget form after drag-and-drop “only specific plugin”
- Recent Comments from Specific Category Widget
- Placing a widget with $wpdb query
- How to make widget appear conditionally
- Ampersand breaking Widget title
- How to allow editing of text in sidebar?
- Shortcode into widget
- Want to add more option in “Sexy Login”
- How to show avatar of current logged in user in a widget
- Got a problem with a widget
- Widget control – putting a slideshow in the widget area
- Unable to see Widget Submenu under Appearance with Class Based WP_Widget
- How to update a widget data?
- Recently changed domain name. Home page widgets are now not in the customize menu yet still being on the page
- Is it possible to dynamically output the name of the widgets?
- I accidentally added a widget area called sidebar 1
- wp_registered_widgets doesn’t contains my widgets
- How can I write this code snippet so that it echo’s the response when submitting empty fields?
- What is the difference between widget object and widget instance?
- My plugin works in home page, but doesn’t work in post page
- Widget text color change
- How to make featured area?
- Checking if widget has title not working
- How to create another widgets.php page
- widget that will do shortcodes that user inputs
- Disable wordpress widget automatically on error
- Can I add a widget to the of my site?
- Widget dynamically add new input field
- WordPress function breaks widget’s markup?
- Registering multiple copies of a widget
- How do I stop out of stock items from appearing on my WooCommerce site when using the Layered Nav widget [closed]
- Single Widget Multi Sidebar
- Add text to Text Widget using Javascript
- Widget on home page displays wrong time compared to same widget on inside pages
- Subpages menu on sidebar plus widgets
- Widgets in PHP files?
- Text Widget Not Working
- Sample widget code which get data(1-5 record) from Wp_Admin panel and display to Homepage(WordPress Custom Theme)
- Unable to add options on dashboard widget ?
- is it possible to create custom widgets page in admin?