WordPress path url in js script file

后端 未结 5 748
北恋
北恋 2020-12-01 02:56

I added custom script:

wp_enqueue_script(\'functions\', get_bloginfo(\'template_url\') . \'/js/functions.js\', \'search\', null, false);

I

5条回答
  •  無奈伤痛
    2020-12-01 03:19

    According to the Wordpress documentation, you should use wp_localize_script() in your functions.php file. This will create a Javascript Object in the header, which will be available to your scripts at runtime.

    See Codex

    Example:

     get_option('siteurl') )); ?>
    

    To access this variable within in Javascript, you would simply do:

    
    

提交回复
热议问题