我正在使用 wp-store-locator 插件,我想在我的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';
但我不想这样。还有其他方法吗?
答案 0 :(得分:0)
您正在寻找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;
答案 1 :(得分:0)
将变量回传到你的javascript中
echo "
<script type = 'text/javascript'>
var pluginURL = '" . plugins_url() . "/store-listings.php';
</script>