简体   繁体   中英

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>

The tag for add images is <img src=""> on the src attribute 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.

What is the return of get_settings() function? ==> name's Image?
I think this code is OK, but you should check the return value of your function.

...place at the beginning of you webpage, near the top with the rest of your PHP/JavaScript:

    <?php

    $image_name = '/images/logo.png';

    ?>

...In this are you place allof your HTML...

    <img src='<?php echo $image_name; ?>'>

Basically, you can have a variable named 'image_name' that you can have be anything.

If you wanted the HREF link area to be a variable that could be changed as well, just do this:

    <?php

    $image_name = '/images/logo.png';
    $image_url = 'http://www.google.com';

    ?>

Then...

    <a href='<?php echo $image_url; ?>' border='0'><img src='<?php echo $image_name; ?>'></a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM