如何在JS中调用插件路径


How to call plugin path in JS?

我正在使用wp商店定位器插件,我想将插件目录路径添加到我的JS中。

html = "<li data-store-id='" + id + "'><div><p>" + storeImg + "<strong>" + store + "</strong><span class='wpsl-street'>" + address + "</span>" + address2 + city + " " + state + " " + zip + "</p>" + moreInfo + "<span><a href='plugin-urlpath/store-listings.php' class='more-details'>More details</a></span></div></li>";
return html;

我该怎么做?插件路径位于html的末尾。

我试过这样:

var pluginURL = 'pluginpathhere';

但我不想这样。还有别的办法吗?

您正在寻找plugins_url()。示例用法:

<?php $url = plugins_url(); ?>

在您的情况下:

html = '<li data-store-id="' + id + '"><div><p>' + storeImg + '<strong>' + store + '</strong><span class="wpsl-street">' + address + '</span>' + address2 + city + ' ' + state + ' ' + zip + '</p>' + moreInfo + '<span><a href="<?php echo plugins_url(); ?>/store-listings.php" class="more-details">More details</a></span></div></li>';
return html;

将变量回声到您的javascript中,如

echo "
<script type = 'text/javascript'>
   var pluginURL =  '" . plugins_url() . "/store-listings.php';
</script>