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?
- Hover Hide-Visible Additional CSS not working in WordPress website, but shows properly in Customize window
- Remove wrapping div and ul from output of wp_nav_menu
- Make Custom Metaboxes Collapse by Default
- Updating WordPress overwriting customization tweaks – strategies?
- Change the login button on the login page
- How to create a page that isn’t accessible via menus?
- How to Save Different Usermeta Fields According to User Role?
- wp_get_archives for a specific category?
- Using WordPress functions on other sites
- Create a customizable child theme
- Custom image size not selectable in uploader
- How to merge all my pages into one, while keeping a menu bar?
- Outputting Page Content in Two Places
- Tag description doesn’t show hyperlink
- How to remove tag cloud from taxonomy admin edit page?
- Post Thumbnail help
- Hide custom field if empty
- Admin Panel – Custom Menu Sub-Item LINK
- Adding custom styles to dropdown in editor
- Add custom user profile field to default WordPress MultiSite registration form
- Is there a way to dynamically get to your uploads folder?
- Updating Existed RocketTheme Theme on WordPress
- Setting custom search engine indexing for a “dynamic WordPress page” with htaccess
- how to add custom css and js on wordpress post editor directly without using .php file
- How to customize core admin pages within a theme?
- URLs and navigation in custom themes
- How to move wordpress to subdomain, keeping only .htaccess and/OR index.php in root domain?
- Load MediaPlayerElement after Infinity Scroll loads more posts
- How to solve this problem with my subdomain?
- how to add custom logo to my template
- WordPress broken after changing URL
- Display posts by combining multiple meta key
- Custom theme – how to link the image without posting it
- How to add active state to the navigation links?
- How do I fix my static page
- Validate user login in php
- optimal taxonomy or custom post types
- Query Product categories what have a custom field
- adding fade on mouseover to images
- Make Widget appear on Dashboard
- Woocommerce dependent attributes
- Displaying all Custom fields on post except some
- WordPress Install – “end of script output before headers” when running simple php script
- How to replace part of shortlink with nothing
- Is there a way to hide a user’s posts from their Activity feed?
- disable lightbox in a plugin [closed]
- Setting up staging area
- Add variable : 1 Week ago
- When is it OK to create a custom table for a plugin? [duplicate]
- How to display product variations on same row
- Redirections all subcategory to a new page