In order to interact with the event “widget-added” , you should enqueue your JavaScript file using “customize_controls_enqueue_scripts” to avoid it being part of the repetitively loading preview iframe ( where $(document) is different from the parent page document).
I was able of interacting with the “widget-added” event using this example :
in theme’s functions.php
function custom_enqueue_scripts(){
wp_enqueue_script( 'custom-script', get_template_directory_uri() . '/js/custom.js',array('jquery','customize-widgets'),'',1 );
}
add_action('customize_controls_enqueue_scripts','custom_enqueue_scripts',10);
JavaScript file :
jQuery(document).ready(function($) {
$( document ).on( 'widget-added', function(event, widget) {
console.log(widget);
});
});
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
- Where to get the unsaved list of widgets in customizer?
- How to enable “shift-click to edit this widget” functionality on a custom widget?
- Remove the widgets tab from theme customizer
- 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
- Extend WordPress 3.8 Site Activity Dashboard Widget to include more comments
- Enabling jquery when dragging available widget to sidebar area
- PHP Coding Standards, Widgets and Sanitization
- Different widgets on different page templates?
- Register multiple sidebars
- How to add a filter to all widget output
- Widget Update Code Not Working
- Reorder dashboard widgets
- Is It Possible to Restore Accidentally Deleted Widgets?
- How Can I Duplicate a Widget?
- How do I create a widget that only allows a single instance?
- How to add class on Widget Title
- Create variable from widget instance
- Why use widgets?
- Completely disabling widgets
- How do I pass arguments to dashboard widget callback functions?
- Theme Customizer – Choose where widget area appears, to let users organise widgets
- woocommerce featured products and categories
- Removing custom widget area WordPress 4.4 [closed]
- Too few arguments to function WP_Widget::__construct(),
- How to change text widget title h2 to h1
- instance is empty in function widget()
- Check which registered sidebar a widget is added to
- Widget code is not working on WordPress.com Hosted Blogs
- Display sidebar only if it has content
- Post-specific widgets in WordPress ‘Twenty Fourteen’ theme
- Excluding specific widgets from default sidebar class
- How to truncate titles in Recent Posts widget?
- Can WordPress Read Its Own RSS Feed?
- Debug errors on sidebar
- Dynamic sidebar based on category
- Widget textarea input gets formatted
- Show widget differently depending on if it’s in the sidebar or footer
- Get posts after today (upcoming events)
- How to pass data from page to widget functions?
- Adding a rich text editor to a widget – specifically CKEditor
- Is it possible to display tag cloud widget by category?
- Widget page is missing from menu and default widgets are not showing
- wp_editor in widget breaks after save (no buttons and visual tab broken)
- How to use a dropdown to populate a list of post from CPT
- Allow shortcode for custom widget
- Registering a stylesheet inside my WordPress widget
- is_tax() not working in Widget Logic [closed]
- How to position custom dashboard widgets on side column
- One register_sidebar function works, the other doesn’t?
- Modify WordPress widgets Screen
- What does apply_filters() do exactly? [duplicate]
- How do I remove/reset all current widgets from the database?
- what is the difference between these two types of widget form method
- Change Woocommerce Product Categories Widget ‘Title’ based on Product Category
- Why isn’t my custom widget outputting any content?
- Sidebar widgets – dynamic CSS : problem with widget-title
- widget not displayed
- Dynamically creating multiple widgets from Mustache templates
- Jquery checkbox -show posts with checked tags
- changing the style of sidebar
- Vimeo Feed gived dead link with RSS widget?
- Preset Widgets ONLY after site is initially created
- Is it possible to add a preview to custom developed Widget?
- How to enable [archives] short code
- How to change widget title in wordpress version 5.8.1?
- why the code html apear in this widget in footer
- A checkbox Option for description in Widget
- My widgets do not save
- Handling dozens of sidebars
- I cannot customize custom widgets anymore after moving WordPress website
- How can I only show a widget prior to a specific date?
- Add sidebar in inner pages
- Widget Areas Still Appearing in WP ADMIN When They Shouldn’t
- Dynamic Width of Widgets
- Inkness theme sidebar
- My Email Newsletter plugin will not configure when I try to import the widget
- Automatically hide Widgets that would lengthen page
- Imported blog page layout messed
- My understrap-child theme doesent have a head.php, footer.php
- How do you submit a widget for the wordpress directory?
- Database size Widget