Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Php Img Src Help!

Featured Replies

Hellllooo! On my word press I'm echo'ing out some stuff onto my page and basically, It will only echo that out if that page is a child of another page. Make sense? Hope it does as I'm new to PHP.

 

<img src="<?php echo the_field('university_image'); ?>" alt="" style="float:left" />

 

BUT, when I echo this out, (or something similar, as I think I may have wrote the code above wrong), it decides to show the image perfectly in the page its echo'd out. But in the pages it is not supposed to be echo'd out, it puts a little 'X' in the top left corner as if the image was not to be found, or if it was moved.

 

Any ideas? How would I make it so the field name 'university_image' would do what I want but will not display a little 'x' when not displayed, so ideally, not call for any image at all.

 

Any help will be greatly appreciated!

Can you show me/us an example of what you aqtually mean?

 

is it perhaps

 

<?php

 

echo '<img src="image source" />';

?>

 

What you mean to echo an image?

  • Author

Right maybe this is a better of explaining:

 

http://university-compare.com/university-guide/anglia-ruskin-university'>http://university-compare.com/university-guide/anglia-ruskin-university

 

thats the link that is echoing the right image.

 

 

BUT, that echo only works if its a child of a certain page, so it only displays when its needed.

 

But where the 'img src' tag is written before the php, the 'img' tag appears in the website everywhere else.

 

so on here: http://university-compare.com/ - there is a 'dead thumbnail' on every page, which is adding <br>'s and pusing the content down..

 

If that makes sense? I cant use

echo '<img src="image source" />';?>

because i've made it so the img src is just an upload to a media 'section', so it will call the field name/label, instead of the image source.

 

Hope that helps my case?

  • Author

Anything inside the php brackets would work, but not the way you said with a normal source.

what's your actual code for the page you linked that doesn't work? The resultant source is showing <img src="" alt="" style="float:left" /> so something's not quite right with the image field. Have you tried just echoing what is in that before the img src statement?

  • Author

what's your actual code for the page you linked that doesn't work? The resultant source is showing <img src="" alt="" style="float:left" /> so something's not quite right with the image field. Have you tried just echoing what is in that before the img src statement?

 

Those links do work? try em again..

 

REally don't do Wordpress much, but can't you just do something like:

 

<img src="<?php echo get_post_meta($post->ID, "Thumbnail", true);?>" alt="custom image" />

 

 

Well I'm using at the moment:

<img src="<?php echo the_field('university_image' );?>" alt="" />

 

But on this link it works fine: http://university-compare.com/university-guide/anglia-ruskin-university'>http://university-compare.com/university-guide/anglia-ruskin-university

 

and on this link it shows a small error image gif(same as every other page): http://university-compare.com/

 

So I cant work out whats wrong, I think if there was a way to display the img src inside the PHP other than the way was said earlier then I wouldn't get that problem, because that php is ONLY echo'd out on that page.

 

So that php anywhere else doesn't display, so that means there is <img src=" " alt="" /> floating about in the page when that certain page isn't being used, make sense?

 

So thats why I'm getting that small gif image on the pages.

Edited by OwenONeill

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.