Sometimes it’s really useful to be able to output HTML in the Customizer that’s not a label or description for a specific control. You may want to output a line break, an image, a button, or simply some additional text.
There isn’t a native Customizer control in WordPress to do this, but you can add your own custom control to output arbitrary HTML. This was a request for the Customizer Library, and the GitHub issue explains the thought process behind the code.
Custom Control
Creating a custom control to output arbitrary HTML is just a few lines of code (label and description could even be removed if you don’t need them):
https://gist.github.com/devinsays/f0ed4a4d52b5f5a72e7b#file-custom-content-php
It’s kind of odd to register the setting since it isn’t actually needed, but WordPress requires a setting in order to output the control.
Output in the Customizer
Once your custom control is loaded, you can output HTML via the Customizer like this:
https://gist.github.com/devinsays/f0ed4a4d52b5f5a72e7b#file-custom-content-example-php
More on Custom Controls
Corey McKrill also wrote about custom content controls and explains the code in more detail.
If you’re looking to make other custom controls, definitely check out the Customizer tutorials by Justin Tadlock. The Kirki library also has a number of useful custom controls.
This just came in handy big time. Thank you, sir!
I wonder why this sort of thing still isn’t part of core yet.
Thanks for sharing, very useful!
Brilliant and simple. Thank you very much!