Add action hook into wp_localize_script
Everything is working as expected. The problem is that your hook is rendering content to the page and you would like to pass that output to the javascript variable included in the JS output. You need to capture the hook output into a variable then add to $data. // buffer output ob_start(); // run hook … Read more