WordPress path url in js script file

后端 未结 5 752
北恋
北恋 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:25

    You could avoid hardcoding the full path by setting a JS variable in the header of your template, before wp_head() is called, holding the template URL. Like:

    
    

    And use that variable to set the background (I realize you know how to do this, I only include these details in case they helps others):

    Reset.style.background = " url('"+templateUrl+"/images/searchfield_clear.png') ";
    

提交回复
热议问题