Wp Customizer event for when a new widget has been added

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 … Read more

Image Upload Widget Issue

Updated Actually, you have to trigger change event to activate the Save button. WordPress widget handler listens to only changes. When you update the input field value with JS, DOM doesn’t trigger any change. That’s why we have to trigger manually. Please check the following code – $(‘.deo-‘ + type + ‘-hidden-input’).val(attachment.url).trigger(‘change’);

Widget html code error

Changes were made to the Text Widget in WordPress 4.8. The editing experiencing was enhanced in some ways but this also caused issues with certain HTML tags and formatting. Fortunately, a new Custom HTML Widget was added in WordPress version 4.8.1. The Custom HTML Widget allows <script> tags, and will not remove certain formatting unlike … Read more

Add custom element ID depending where the widget place is, sidebar or footer

Solved it by following the advice from @mmm. Using $args[“id”] did the trick. Using $args[“id”] will return the following: post-sidebar footer-first With a little change, my final code is: public function widget( $args, $instance ) { extract($args); // … <div id=’instafeed-<?php echo explode(“-“, $args[“id”])[0] ;?>’ class=”c-widget-instagram”></div> <?php echo $after_widget; } The result is: <div id=’instafeed-post’ … Read more

register widget class not written in theme

include that file in your functions.php file like require_once(‘includes/custom-widgets.php’); then you can call add_action() hook, in your case add_action(‘widgets_init’, ‘SER_register_widgets’); . the idea is to make that function ( ser_register_widgets ) visible in current php file ( functions.php file in this case )