Search code examples
phpimagehref

How do I call in an image in php using a href?


I have a bit of code that, using php, I want it to call in an image rather than what it is currently calling in (which is 'echo bloginfo('name');). However, I am sadly PHP illiterate and have no idea how to do this with the 'a href' posted below. Could anyone help me call to /images/logo.png? Many thanks in advance!

<h1><a href="<?php echo get_settings('home'); ?>"><?php echo bloginfo('name'); ?></a></h1>

Solution

  • The tag for add images is <img src=""> on the srcattribute you need to write the url of the image you want (in your case /images/logo.png) so, replacing the code you pasted

    <h1><a href="<?php echo get_settings('home'); ?>"><img src="/images/logo.png"></a></h1>
    

    Take into account that the path to the image you are using now is a relative one (relative to the document requiring the image) so you probably want to have the absolute url instead.