Mike.Whitehead Mike.Whitehead - 1 year ago 53
PHP Question

Wordpress - correct php link for images in media library

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>[email protected]</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.

Answer Source

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

<img src="<?php echo home_url(); ?>/wp-content/uploads/2017/07/phone.png">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download