Wordpress 本地开发站点主题资产指向安装目录之外
Wordpress local development site theme assets point outside of install directory
在自定义 WordPress 网站上工作,其中主题上的所有链接都是这样的:href="/wp-content/...",这似乎对其他开发人员有效,但它不起作用在我的本地开发设置 (MAMP) 上。所有这些指向图像和页面的链接最终都指向我本地服务器的根目录,而不是安装所在的子目录,这导致找不到很多文件和主题资产。
我所需要的只是做一些快速的前端并在不编辑模板的情况下提交,以至于它成为其他开发人员的问题。
我想知道是否有临时解决方案,使链接转到子目录而不是根目录?即:'http://localhost/WPSITE/wp-content/...', instead of 'http://localhost/wp-content/...'
希望它有意义!
您可以在 footer.php
文件中使用此脚本
<script>
jQuery(document).ready(function(){
var find_str = "/wp-content/";
var replace_with = "http://localhost/WPSITE/wp-content/";
$('img').each(function (index, value) {
var src = jQuery(this).attr('src');
if(src.indexOf(find_str) != -1) {
console.log(find_str);
src = src.replace(find_str, replace_with);
jQuery(this).attr('src', src);
}
});
});
</script>
在自定义 WordPress 网站上工作,其中主题上的所有链接都是这样的:href="/wp-content/...",这似乎对其他开发人员有效,但它不起作用在我的本地开发设置 (MAMP) 上。所有这些指向图像和页面的链接最终都指向我本地服务器的根目录,而不是安装所在的子目录,这导致找不到很多文件和主题资产。
我所需要的只是做一些快速的前端并在不编辑模板的情况下提交,以至于它成为其他开发人员的问题。
我想知道是否有临时解决方案,使链接转到子目录而不是根目录?即:'http://localhost/WPSITE/wp-content/...', instead of 'http://localhost/wp-content/...'
希望它有意义!
您可以在 footer.php
文件中使用此脚本
<script>
jQuery(document).ready(function(){
var find_str = "/wp-content/";
var replace_with = "http://localhost/WPSITE/wp-content/";
$('img').each(function (index, value) {
var src = jQuery(this).attr('src');
if(src.indexOf(find_str) != -1) {
console.log(find_str);
src = src.replace(find_str, replace_with);
jQuery(this).attr('src', src);
}
});
});
</script>