theme development - How to echo inside the js file with wp_localize_script?

admin2025-06-05  7

I have used wp_localize_script() to pass a variable to a javascript file.

var countries = [searchresults.data];

The variable is getting passed but I want it in a js file like below:

var countries = [item1,item2,item3];

The variable is correct searchresults.data = item1,item2,item3, but the countries variable has to be like var countries = [item1,item2,item3]; iIam not able to do. Please help


This is the $data that I passed

 $data = array(
      'data' => $searchresult,
    );
 wp_localize_script( 'searchautocompleter', 'searchresults', $data );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749113405a316475.html

最新回复(0)