WordPress path url in js script file

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

    If the javascript file is loaded from the admin dashboard, this javascript function will give you the root of your WordPress installation. I use this a lot when I'm building plugins that need to make ajax requests from the admin dashboard.

    function getHomeUrl() {
      var href = window.location.href;
      var index = href.indexOf('/wp-admin');
      var homeUrl = href.substring(0, index);
      return homeUrl;
    }
    

提交回复
热议问题