Creating dropdown-pages control with Customize JS API

All base controls from the core can be created with the Customize JS API, except the dropdown pages control, that renders as a select list with all pages of the site. This means, we usually need to create that control via the PHP API at the moment.

As a reaction to a wordpress.stackexchange.com question, Weston Ruter wrote a plugin that lets us create the dropdown pages control via the JS API (some details on that can be found in his answer to the question). The important part is the print_control_templates() method that creates a control template for the JS API to use when it should create a dropdown-pages control. This template is included in the customizer with the following call in the init() method:

add_action( 'customize_controls_print_footer_scripts', array( $this, 'print_control_templates' ) );
Code language: PHP (php)

Leave a Reply

Your email address will not be published. Required fields are marked *