【问题标题】:get_stylesheet_directory_uri() and get_template_directory_uri() not returning "http"get_stylesheet_directory_uri() 和 get_template_directory_uri() 不返回“http”
【发布时间】:2017-09-04 18:49:21
【问题描述】:

我使用我的 wordpress 网站的 xampp 制作了一个本地副本。主题是我写的。 在本地,每个使用 get_template_directory_uri() 或 get_stylesheet_directory_uri() 的图像链接都被破坏,因为它缺少“http”前缀。如果我手动添加,则图像显示正确。

这是代码: <?php echo get_stylesheet_directory_uri() . '/images/myimage.jpg' ?>

上述函数在线生成:
http://www.mywebsite.it/wp-content/themes/mytheme/images/myimage.jpg"
本地在 xampp 他们生成:
localhost/myfolder/wp-content/themes/mytheme/images/myimage.jpg
和图像不显示。如果我在localhost 之前手动添加http://,它就可以工作。

有趣的是,函数 get_template_directory_uri() 也在functions.php中用于对一些样式表进行排队,即使在本地,它也会生成以http开头的正确url。

我不知道如何修复此问题,我不想在本地更改此处的每个链接,并且必须记住在将其上线之前将其修复回来。对不起我的英语。

编辑:我可以通过转义网址自动添加“http”,使用此代码
<?php echo esc_url(get_stylesheet_directory_uri() . '/images/myimage.jpg') ?>
这在本地解决了问题,并且不影响在线输出,因此我可以像这样同步代码......不过,我不知道它为什么会这样。

【问题讨论】:

  • 这里有问题。我已经多次使用 localhost 并且从未遇到过这个问题。您的网站是否添加了任何“stylesheet_directory_uri”、“theme_root_uri”或“content_url”过滤器?
  • @user8262086 不,它没有

标签: php wordpress image


【解决方案1】:

请在设置

中检查WordPress地址(URL)站点地址(URL)

【讨论】:

    猜你喜欢
    • 2018-10-31
    • 2016-01-29
    • 2017-06-06
    • 2015-10-26
    • 2017-10-12
    • 2020-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多