3

In wordpress theme customizer, we need to define a setting to add a control. My question is can we add more than one control under a setting?

If yes, how to access the values of those controls. In documentation i found that we can read values of settings. get_theme_mod( 'site_logo' ), but its not mentioned how to read value of controls.

If we can not add more then one control under one setting, what's the benefit of having settigns?

I believe i have missed something somewhere, that describes how both settings and controls differentiate with each other.

Any help is appreciated!

2

I would say no, because a setting needs a unique ID, if you have two controls with the same ID, they will set the same name attribute to two different inputs in the controls and conflict so only one value will be saved.

Actually do not see much point in having them separated at all, you can't really use one without the other in any meaningful way I can see, but maybe there is a use case for keeping them separate.

Instead if you wanted more control over a single setting you would need to create a custom control class with multiple UI inputs and javascript in it to help calculate a single setting value. But be sure to only use the setting name attribute on the actual element where the final value will be. Otherwise, better to just create another setting with it's own control.

  • Then what's the point in having two different things, settings and controls? Wordpress could have created only settings, or only controls. We will need to write less code in that case, and code will be cleaner too. – Alok Jain Apr 7 '16 at 13:04
  • Like I said I don't see much point in it myself, but maybe it adds slightly more flexibility to the Customizer API. For example you might be able to add a setting without a control, and a bunch of controls with dummy settings that actually affect just the first setting via javascript? At the very least it gives you a distinction between the arguments you pass to the setting (and so affect how the option may be used) and those you pass to the control (and so only affect the setting inputs on the customizer screen.) – majick Apr 8 '16 at 2:42
0

A control is a visual representation of a setting. First you define a setting then use its setting id when defining a control. It should be possible to link multiple controls to a single setting but I haven't tested it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.