[wp-trac] [WordPress Trac] #41126: Customizer does not work if both wp_footer() and wp_head() functions are present in the theme.

WordPress Trac noreply at wordpress.org
Thu Jun 22 21:01:44 UTC 2017


#41126: Customizer does not work if both wp_footer() and wp_head() functions are
present in the theme.
--------------------------+------------------------------
 Reporter:  mdifelice     |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Customize     |     Version:  trunk
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  administration
--------------------------+------------------------------

Comment (by westonruter):

 @mdifelice if you have a template that lacks `wp_head()` and
 `wp_footer()`, then currently you have to manually print the required
 scripts and call the methods that would normally get output. For example,
 the following should account for most of what is required:

 {{{#!php
 <?php
 global $wp_customize;
 if ( is_customize_preview() ) {

         // Enqueue assets for components.
         $wp_customize->selective_refresh->enqueue_preview_scripts();
         if ( $wp_customize->widgets ) {
                 $wp_customize->widgets->customize_preview_enqueue();
         }
         if ( $wp_customize->nav_menus ) {
 $wp_customize->nav_menus->customize_preview_enqueue_deps();
         }

         // Print customize-preview style and all styles that depend on it.
         $styles = array( 'customize-preview' );
         foreach ( wp_styles()->registered as $handle => $asset ) {
                 if ( in_array( 'customize-preview', $asset->deps, true ) )
 {
                         $styles[] = $handle;
                 }
         }
         wp_print_styles( $styles );

         // Print customize-preview script and all scripts that depend on
 it.
         $scripts = array( 'customize-preview' );
         foreach ( wp_scripts()->registered as $handle => $asset ) {
                 if ( in_array( 'customize-preview', $asset->deps, true ) )
 {
                         $scripts[] = $handle;
                 }
         }
         wp_print_scripts( $scripts );

         // Call methods normally done by wp_head and wp_footer.
         $wp_customize->remove_frameless_preview_messenger_channel();
         $wp_customize->customize_preview_settings();
         $wp_customize->customize_preview_loading_style();
         $wp_customize->selective_refresh->export_preview_data();
         if ( $wp_customize->widgets ) {
                 $wp_customize->widgets->print_preview_css();
                 $wp_customize->widgets->export_preview_data();
         }
         if ( $wp_customize->nav_menus ) {
                 $wp_customize->nav_menus->export_preview_data();
         }
 }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41126#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list