[wp-trac] [WordPress Trac] #46334: wp_localize_script did not output anything in wp_print_footer_scripts hook although document suggested that it should be working

WordPress Trac noreply at wordpress.org
Thu Aug 14 08:51:24 UTC 2025


#46334: wp_localize_script did not output anything in wp_print_footer_scripts hook
although document suggested that it should be working
---------------------------+-------------------------
 Reporter:  simongcc       |       Owner:  (none)
     Type:  defect (bug)   |      Status:  closed
 Priority:  normal         |   Milestone:
Component:  Script Loader  |     Version:  4.9.8
 Severity:  major          |  Resolution:  worksforme
 Keywords:                 |     Focuses:
---------------------------+-------------------------
Changes (by jonsurrell):

 * status:  new => closed
 * resolution:   => worksforme
 * milestone:  Awaiting Review =>


Comment:

 Hi @simongcc. It seems like there's a problem with the priority of the
 filter you're adding:

 {{{#!php
 <?php
 add_action( 'wp_print_footer_scripts', 'set_member_meta', 20 );
 }}}

 This filter has a priority `20`.
 [https://core.trac.wordpress.org/browser/tags/6.8.2/src/wp-includes
 /default-filters.php#L364.
 [https://core.trac.wordpress.org/browser/tags/6.8.2/src/wp-includes
 /default-filters.php#L364 The scripts are actually printed as part of this
 action] with the default priority of `10`:

 {{{#!php
 <?php
 add_action( 'wp_print_footer_scripts', '_wp_footer_scripts' );
 // https://core.trac.wordpress.org/browser/tags/6.8.2/src/wp-includes
 /script-loader.php#L2266
 function _wp_footer_scripts() {
   print_late_styles();
   print_footer_scripts();
 }
 }}}

 The data is being attached to the script _after_ the script was printed,
 because the `20` priority action will run later. The following should fix
 your example by using a lower priority:

 {{{#!php
 <?php
 add_action( 'wp_print_footer_scripts', 'set_member_meta', 5 ); // Use 5
 instead of 20.
 }}}

 Hope that helps!

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


More information about the wp-trac mailing list