Using wp_localize_script in template file – is it secure?

Input/output related security issue can be roughly sorted into two buckets:

  • someone manages to read information they are not supposed to;
  • someone manages to write information they are not supposed to.

Localize is not capable of writing anything into site, so you are safe on that front.

On the read side it’s not much different from just echoing things into page source (which it’s essentially doing). The only thing you need to be careful about is that data provided cannot be manipulated by user/input.

For example page title should be precisely for the page being processed and there should be no holes allowing it to return title for a different page (which might be private and such).