Script localization method for custom modules?

I love the add_js() method for only enqueueing javascript when my module is on the page. Is there a comparable method like wp_localize_script() that can be used to include extra variables into the javascript when it’s loaded? Thanks!


You should use the enqueue_scripts module method then you can use enqueue and localize normally.

public function enqueue_scripts() {
	wp_enqueue_script( 'test-js', '' );
	wp_localize_script( 'test-js', 'test', array( 'test' => 'test' ) );