Stop Using wp_localize_script to Pass Data

If you’re using wp_localize_script() to pass data from PHP to JavaScript, you’re using the wrong tool. Despite what countless tutorials suggest, it was built for making JavaScript strings translatable and not for data passing. WordPress gave us wp_add_inline_script() nearly a decade ago specifically for this purpose, and it’s time we started using it.

6 Likes