这是它在页面中的作用: 我如何更改代码以强制 wordpress 从 ht-6ren">
gpt4 book ai didi

php - 如何使用 the_field 从 https 加载图像

转载 作者:太空宇宙 更新时间:2023-11-03 13:39:41 25 4
gpt4 key购买 nike

在 Wordpress 中,我有一行代码从 http 加载图像,我希望它从 https 加载图像。

<img class="img_notif" src="<?php the_field('small_img',$post->ID); ?>" />

这是它在页面中的作用:

<img class="img_notif" src="http://www.startupacademy.ro/wp-content/uploads/2013/06/antreprenor-de-succes-mic.jpg" />

我如何更改代码以强制 wordpress 从 https 加载图像?

最佳答案

由于 WP 似乎没有本地方法来执行此操作(我震惊 </sarcasm>),您只能使用 PHP 进行替换。将您的行更改为

<img class="img_notif" src="<?php str_replace('http', 'https', the_field('small_img',$post->ID)); ?>" />

关于php - 如何使用 the_field 从 https 加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27894164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com