douyi1982 2017-07-26 17:20
浏览 62
已采纳

Wordpress - 正确的媒体库中的图像的PHP链接

I'm finalising a wp site I've built on my local server and removing all localhost links. I've added all the_permalink tags for pages but I'm struggling with the links for my img tags. I've tried <?php get_attached_media( 'ID' ) ?> and I've tried <? php wp_get_attachment_link() ?> and <? php wp_get_attachment_image() ?> but none seem to work.

What am I doing wrong? This is the code in my header file, for example, so its all standard code -

header.php

<div class="left-header">
            <img src="http://localhost:8888/wp-content/uploads/2017/07/Logo.png" alt="logo" id="logo" style="width:250px;height:30px;">
        </div>
    <div class="right-header">
         <div class="right-header-top">
            <div id="contact">
                <img src="http://localhost:8888/wp-content/uploads/2017/07/phone.png">
                <p>0113 220 5265</p>
                <img src="http://localhost:8888/wp-content/uploads/2017/07/email.png">
                <p>hello@media.co.uk</p>
            </div> 

Pretty much all the images I'm looking to change are in img tags.I'm sure this is a straightforward fix but I'm having a real brain freeze at the moment.

  • 写回答

1条回答 默认 最新

  • dougu1952 2017-07-26 17:28
    关注

    Should be <?php echo home_url(); ?>, for example:

    <img src="<?php echo home_url(); ?>/wp-content/uploads/2017/07/phone.png">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1