You need to enqueue a separate script on a different action with a different dependency.
/**
* Enqueue styles and scripts for the Customizer pane.
*/
function mytheme_customize_pane_enqueue() {
wp_enqueue_script( 'mytheme-customizer-control',
get_template_directory_uri() . '/js/customizer-control.js',
array( 'customize-controls' ), '20180924', true );
}
add_action( 'customize_controls_enqueue_scripts', 'mytheme_customize_pane_enqueue' );
The JS looks like this:
( function( wp, $ ) {
wp.customize.control( 'mytheme_option', function( control ) {
control.container.on( 'click', '.element_class', function( event ) {
event.stopPropagation();
//control.doNotice( '' );
//control.applyPresetValues( $( this ).data( 'revert' ) );
} );
} );
} )( wp, jQuery );
Related Posts:
- New WP_Customize API – how does it work under the hood?
- Disable Visible Edit Shortcuts in the Customizer
- How to Add Customizer Setting in Child Theme
- customize_register with Multiple controls/settings – how to get values?
- Manipulating post meta in the customizer
- Widgets not working in Customizr but working in Appearance
- In the new Theme Customizer API, how to send a value from the front back to the admin panel?
- get_theme_mod(); returns nothing
- How to get input_attrs in the sanitize function?
- How to change in customizer the “site identity” tab required capabilities
- Customizer image control default value showing in customizer but not on frontend
- Customizer: How do you add HTML to control labels?
- Add new Control to Customizer to modify Headings (h1, h2, h3…) Color
- How to extend nav-menu-item-control data in Appearance > Customize?
- What will happen to the additional CSS when the theme is updated?
- Convert an theme options page to use in customize.php also?
- Add more then one site logo – custom-logo theme support
- Hide devices selection from customizer?
- Fatal error in wp-admin/customize.php after fresh install due to null $wp_customize
- Enabling Additional CSS / custom-css
- Can not sanitize select control in customize api
- For a specific theme, how do I build a list of all the possible theme modification names?
- Save & Publish disabled for two dimensional array Customizer
- Allow guests to use WP Customizer but disable save button
- How do I remove a customiser option from a parent theme in a child theme?
- How to add css option to Header Image customizer?
- Trigger Customizer Publish (save) Action
- How to edit alternate inactive themes in “Appearance -> Customise” screen?
- Is it necessary to prefix theme_mod, section id and panel id in the customizer?
- Hide Customizer’s Widget Choices From The List
- theme customizer – can a single option pass multiple values?
- How to remove Customizer’s Section and move Control straight to Panel using Child Theme
- Remove Customizer Control Choices (Type: Radio Array) using Child Themes
- Dynamic Control in customiser
- Is it possible to rename a customizer control heading?
- Is it possible to add custom badges to product attributes conditionally, based on custom field?
- Will WordPress updates remove Gutenberg Additional Classes?
- Easily add custom HTML outside the main container?
- Customizer options limited to specific user roles?
- Can’t Customize WordPress Page
- WordPress Customizer: Check for value of CSS selector and replace it
- In wordpress customizer api adding div wrap to control
- Apply `the_content’ filter to theme customisation live preview
- retrieve theme custom settings
- Multiple Customizers
- Which IDE best for WordPress Development? [closed]
- Refresh Customize Section (not preview)
- Do i need to use PHP in customizer api?
- Where did I put this one line of css?
- Looking for a lightweight theme using WP3 new tags and features (not 2010) [closed]
- How can I get posts in a subcategory to display on it’s parent categories archive page?
- Creating my own Admin Forms in a WordPress CMS?
- Best practices for A/B testing?
- Editing the Number at the end of Page URLs / Editing Page Slugs
- simple wp_insert_post example
- Redirect members to custom page upon logging in through WP admin
- WordPress Customizer: How can you have multiple active callbacks on one control?
- Integrating MailChimp newsletters as post
- What is WordPress file encoding?
- WP_Query with the “offset” argument
- Adding “Interesting Tags” & “Ignored Tags” like StackOverflow.com in a WordPress Blog?
- Auto add taxonomy if post has category
- Add a containing DIV to core Gutenberg blocks
- Are there any security issues with setting the WP_INSTALLING constant to true?
- Name/Word Replacement Plugin
- Get page ID outside the loop, matching menu ID
- Author Tracking Code!
- Custom comments list, right depth
- Order posts with a custom field but also without
- WordPress 3.0.1 on IIS 6 Web Server PermaLink Issues
- Change Notice of Password change email subject?
- Deleting my old WordPress site. – issues
- How to append custom text to the output of ‘categories widget’?
- How to assign a custom post title to be the post ID?
- Creating custom page template
- Which delete query is better with prepare or delete
- How to add page content into another page
- Remove Sidebars from page
- Creating a “Delete”-Button for Metadata userspecific
- Change default Video Player without Plugin
- Changing update message from Newspaper child theme
- Custom default settings for WP native Gallery Block
- export and import wordpress customization
- How can i add customisation of text to my theme?
- Can I overwrite custom taxonomy FROM “public” TO “false”
- Trying to customise 2011 Child Theme Background Colour
- the temporary save folder is wrong
- URL issue after setting up Custom Structure in Settings >> Permalinks
- Can I upload my self hosted WordPress website on GitHub as a project? [closed]
- Need to replace some text string on a title
- Custom roles and capabilities media not work right
- How do i edit text that is not in the customization menu
- How do I map two domains to the same wordpress installation?
- Where should I put this custom data?
- how to register / add multiple options into one field in wordpress?
- Custom WP deactivate an email activation link sent to user’s email.
- WordPress Customize panel – accessing the values
- Changes to code not displaying
- Permalink Listing WordPress
- Has the table name in SQL for WordPress changed from WP_posts to WPCS_post?