Customizer Control: Arbitrary HTML

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.

About Devin

I am a developer based in Austin, Texas. I run a little theme shop called DevPress and help manage a WooCommerce shop with Universal Yums. Find me on twitter @devinsays.

3 Responses

Leave a Reply