The solution is to simply enqueue the JS value syncing snippet so that it is added in the customizer pane (customize.php
) instead of the customizer preview window (on the frontend). In other words, enqueue your JS at customize_controls_enqueue_scripts
instead of wp_enqueue_scripts
. Here’s one snippet:
wp.customize( 'field1', 'field2', function( field1, field2 ) {
field1.bind( function( value ) {
field2.set( value );
} );
} );
And here’s an even more succinct example that does the same thing:
wp.customize( 'field1', 'field2', function( field1, field2 ) {
field2.link( field1 );
} );
Nevertheless, if you have the same value stored in multiple settings, why not just re-use the same setting in multiple places?
Related Posts:
- Customizer JS API
- Is it Possible to Extend WP Customize JS Methods?
- wp.customize.bind ready event not fired
- Detecting WordPress Customizer Panel
- wp_customize_support_script – do I need it?
- Customizer – instantiating settings and controls via javascript
- Customizer JS API: Defining control settings
- Customizer JS API: Adding Setting Dynamically Not Working
- Customizer: When to use customize_preview_init VS customize_controls_enqueue_scripts
- How to overwrite JS variable with wp_localize _script?
- Theme Customiser not live previewing changes on pseudo elements
- the Customizer – proper way to instantiate an image upload control via javascript
- Preserve Javascript Through Customizer Preview Navigation
- How to check if customize previewer is refreshing?
- JavaScript in WordPress Customizer
- Customizer JS API: Adding a “dropdown-pages” control
- Accessing customizer values in javascript
- Running JS after theme customizer finished initialization
- customize_preview_init: listening for any changes from Customizer preview area
- How to conditionally show/hide controls & sections in WordPress customizer?
- Multiple Conditional Controllers
- WordPress customizer get control
- Using webpack to add customizer live preview functionality – wp.customize is not a function
- Adding and removing hidden buttons from WordPress Customizer Tinymce widget editor using javascript API
- Get a default value of the Customizer setting using wp.customize API (JS)
- How to add customizer control via javascript ( wp.customizer.control.add )
- Load page in customizer preview on panel click?
- Customizer JS API: Defining active_callback for a section
- Adding Code into Theme Customizer Header
- Custom JS text area in customizer is being formatted wrong in document
- customize-controls.js – extend api.previewer
- Multiple jQuery inputs or binds in Customizer Control Javascripts
- Show sections based on a control in WordPress Customizer using JS API
- How do I add a class to Customizer preview based on class of Customizer control? (Customizer Javascript API)
- LayersWP Customizer White Blank Screen
- Get a default customizeAction text for a section using Customizer JS API
- Receive “menu-toogle” event from section menu in customizer
- How to use Redirect in the new react-router-dom of Reactjs
- How to fix “Cannot read property ‘addEventListener’ of null” error [duplicate]
- What does [object Object] mean?
- Remove class using jQuery
- How do I check whether a checkbox is checked in jQuery?
- Babel 7 – ReferenceError: regeneratorRuntime is not defined
- How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
- How can I create a two dimensional array in JavaScript?
- Does JavaScript pass by reference?
- How to add jQuery code into HTML Page
- TypeError: Router.use() requires middleware function but got a Object
- jquery SlideToggle effect in upward direction?
- Deleting array elements in JavaScript – delete vs splice
- How can I determine if a variable is ‘undefined’ or ‘null’?
- Cannot find module ‘@angular-devkit/core’
- iFrame onload JavaScript event
- Node.js Error: connect ECONNREFUSED
- How to move an element into another element?
- Is there an arraylist in Javascript?
- How to convert JSON object to JavaScript array?
- How can I display a JavaScript object?
- JSLint says “missing radix parameter”
- How to move all HTML element children to another parent using JavaScript?
- How to print HTML content on click of a button, but not the page?
- explode string in jquery
- Simple average function in Javascript
- How to uncheck a radio button?
- How can I extract a number from a string in JavaScript?
- Angularjs: Error: [ng:areq] Argument ‘HomeController’ is not a function, got undefined
- Truncate a string straight JavaScript
- Is there a way to get element by XPath using JavaScript in Selenium WebDriver?
- Get class list for element with jQuery
- Object Dump JavaScript
- How can JavaScript save to a local file?
- Generating PDF files with JavaScript
- How to disable auto-start of “Node.js: Server-side JavaScript” when using Adobe Dreamweaver?
- How to disable button in React.js
- How do I call a JavaScript function on page load?
- Documentation for using JavaScript code inside a PDF file
- Glidejs with WordPress
- REST API: Backbone and custom endpoint
- How to refresh Theme Customizer after change color inside wpColorPicker?
- Can I make use of word-count.js in my own code?
- “Password Strength Unknown” Registration Issue
- How do I add custom attributes to javascript tags in WordPress?
- Min And Max Date With Date Format In Elementor Form Not Working
- Strange gibberish JavaScript in Editor – site hacked?
- Building a slide down search box in wordpress
- javascript conflict
- How to load JS for specific screen size using wp_enqueue_script?
- Video script issue, JavaScript attribute remains ‘undefined’
- Why does a on Comment edit page submit the page?
- Where to paste Google Map Snippet / JavaScript / CSS for WordPress integration
- TinyMCE Javascript URL Question
- Setting Variable Path to Template Directory inside Script
- Dynamically add Js
- Contact Form 7 Conditional redirect
- How do i load javascript on a specific custom post template via functions.php?
- Can’t change javascript files
- Live Time on WP showing weirdly [closed]
- Google Map JavaScript error after migrating
- Table block variation with header section activated
- How can I look at/edit what’s being sent to post.php when I hit the publish/update button?