Purpose of this demo is to demonstrate, for the theme developer, how to use the customizer postmessage transport and a preview script to toggle complex theme elements on or off.

In this demo I’ll toggle displaying the author and post date.

Theme code:

When the post meta is toggled off, the theme will create an post meta wrapper without the post meta html, and the preview script doesn’t have anything to toggle:

I solve this by adding the missing html using jQuery.prependTo(). The html is just for the preview and will not be added to the theme:

You’ll find a complete demo at GitHub