使用php为wordpress中的images文件夹设置根目录
我的问题是为图像设置根变量,而不使用php在Wordpress中写入所有路径。 我的情况是:使用php为wordpress中的images文件夹设置根目录,php,wordpress,path,root,Php,Wordpress,Path,Root,我的问题是为图像设置根变量,而不使用php在Wordpress中写入所有路径。 我的情况是: <img src="http://localhost/business/wp-content/themes/enigma-child/images/sottocategorie/animaliDomestici/cane.jpg" class="img-thumbnail img-responsive"> 我想要这种情况($root=): 在wordpress中,我在哪里设置这个根
<img src="http://localhost/business/wp-content/themes/enigma-child/images/sottocategorie/animaliDomestici/cane.jpg" class="img-thumbnail img-responsive">
我想要这种情况($root=):
在wordpress中,我在哪里设置这个根变量?有没有一种方法可以从图库中获取图像?
Thx for answers因为您是从子主题引用的,所以动态调用图像的方式是使用
get\u stylesheet\u directory\u uri()
函数
例如,/images/image.png“alt=“your image”>
对于$root作为变量,最好将其作为全局变量插入functions.php或header.php中。这样您就不会修改核心代码,而是从子主题进行扩展
我测试了您建议的代码,但它不起作用,因为我的情况是在交换机中使用img标记。我显示了我的情况:
案例1:echo(Animali domestic);echo(“/images/sottocategorie/animalidometic/cane.jpg>”);中断
您尝试使用/images/image.png“alt=”image“>
这是可行的,但是使用html格式的php代码。我的问题是将html代码反向转换为php,我无法阅读您向我展示的方式。请看这张图片以了解我的问题:您可以尝试使链接路径相对,就像这样
。我尝试使链接路径相对,但不起作用。显示链接的try相对路径:。问题出在哪里?无法很好地解释PHP开关内的html代码?
<img src="root/images/sottocategorie/animaliDomestici/cane.jpg" class="img-thumbnail img-responsive">