使用Wordpress get_option设置图像的SRC

I am trying to use the get_option() function in Wordpress to set the SRC of an image in a theme file. The file is index.php, and represents the homepage.

The current image code is:

<img class="outside-collage-image" <?php echo 'src="'.get_option('article-image-1').'"'; ?>>

However, the image doesn't display, and when I inspect it, it simply says src(unknown) where it should have the proper SRC

I have tried a myriad of fixes, including leaving the SRC out of the php area and simply calling the function, but it doesn't seem to work.

The oddest part is, if I put on the page <p><?php echo 'src="'.get_option('article-image-1').'"'; ?></p> to check the output, it outputs into the <p> the proper code: src="http://image-site.com/my-image.jpg" (obviously the link to the image is fake, but the point is, it's a valid link.)

Any idea what could be causing this?

展开翻译

译文

我正在尝试使用Wordpress中的get_option()函数在主题文件中设置图像的SRC。 该文件是index.php,代表主页。</ p>

当前图像代码为:</ p>

&lt; img class =“outside -collage-image“&lt;?php echo'src =”'。get_option('article-image-1')。'''; ?&gt;&gt; </ code> </ p>

然而,图片没有显示,当我检查它时,它只是说 src(unknown)</ code>其中 它应该有适当的SRC </ p>

我已经尝试了无数的修复,包括将SRC从php区域中取出并简单地调用该函数,但它似乎不起作用。< / p>

最奇怪的部分是,如果我把页面&lt; p&gt;&lt;?php echo'src =“'。get_option('article-image-1')。 '“'; ?&gt;&lt; / p&gt; </ code>检查输出,它输出到&lt; p&gt; </ code>正确的代码: src =“http:// image-site。 com / my-image.jpg“</ code>(显然,图片的链接是假的,但重点是,它是一个有效的链接。)</ p>

任何想法可能导致什么 这个?</ p>
</ div>

dqqvravff05370501
dqqvravff05370501 问题是,我不想逃避HTML-我希望它作为实际的HTML链接输出。
接近 3 年之前 回复
dongtuojuan8998
dongtuojuan8998 尝试使用此代码<imgclass=“outside-collage-image”src=“<?phpechoesc_url(get_option('article-image-1'));?>”'>
接近 3 年之前 回复

2个回答

You can try this to get the image article-image-1.jpg in your root.

 <img class="outside-collage-image" src="<?php echo get_site_url().'/article-image-1.jpg'; ?>">

展开翻译

译文



您可以尝试使用它来获取根目录中的图像article-image-1.jpg。</ p>

< pre> &lt; img class =“outside-collage-image”src =“&lt;?php echo get_site_url()。'/ article-image-1.jpg';?&gt;”&gt;
</ 代码> </ pre>
</ div>

dongzhun8449
dongzhun8449 问题是,SRC需要能够手动设置并随时通过外部设置进行更改。
接近 3 年之前 回复

It turns out that I screwed up, and the above function works just fine. I was simply applying it to the wrong image, and didn't realize that until looking at it a day later, when it wasn't 1:30 AM and I wasn't so tired. Thanks to all that answered.

headdesk

展开翻译

译文



事实证明我搞砸了,上面的功能运行得很好。 我只是把它应用到了错误的图像上,并且直到一天后才看到它,直到凌晨1:30才发现它并没有那么累。 感谢所有回答。</ p>

headdesk </ em> </ p>
</ div>

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问