Using WordPress ‘customize_themes_print_templates()’ PHP function

The customize_themes_print_templates() WordPress PHP function is responsible for printing JavaScript templates for the theme-browsing user interface in the WordPress Customizer.

Usage

To use the customize_themes_print_templates() function, simply call it without any parameters:

customize_themes_print_templates();

Since this function doesn’t accept any parameters and doesn’t return any values, it doesn’t provide an output as such. Its role is to output the necessary JavaScript templates to the webpage.

Parameters

  • This function does not accept any parameters.

More information

See WordPress Developer Resources: customize_themes_print_templates()

This function is part of the WordPress core, and as such, it’s available in all versions of WordPress since its implementation.

Examples

Call the function

This simple usage of the function triggers the printing of the JavaScript templates.

// Trigger the printing of JS templates for the theme-browsing UI
customize_themes_print_templates();

Use inside a function

In this example, we create a function that calls customize_themes_print_templates() when a certain condition is met.

function my_custom_function() {
    if (is_customize_preview()) {
        // Print JS templates for theme-browsing UI if in customizer preview
        customize_themes_print_templates();
    }
}

This example hooks the function into the ‘customize_controls_print_footer_scripts’ action, to print the templates in the footer.

add_action('customize_controls_print_footer_scripts', 'customize_themes_print_templates');

Removing the function from an action hook

This example removes the function from the ‘customize_controls_print_footer_scripts’ action.

remove_action('customize_controls_print_footer_scripts', 'customize_themes_print_templates');

Check if function exists

This example checks if the function exists before calling it.

if (function_exists('customize_themes_print_templates')) {
    // Function exists, so print the JS templates for theme-browsing UI
    customize_themes_print_templates();
}