How to make and image clickable in PHP

9k views Asked by At

I would like to add a static image to my single-package.php template on my travel website.

I have included the image like this:

<?php

$image = "http://dev5.4loopdigital.co.za/wp-content/uploads/2015/06/servicesaccomm.jpg";  
$width = 960;
$height = 300;
echo '<img src="'.$image.'" style=width:"' . $width . 'px;height:' . $height . 'px;">';

?>

What must I add to make that image a clickable image that opens up that same image in a new tab/window in full size?

Thanks so much!

2

There are 2 answers

2
Vineet Kosaraju On

Currently you just have the image - what you want to do is also make the image wrapped in a link, so that when you click the image it takes you to that link's page. This can be done using the a HTML tag and the href attribute.

The following code works for me:

<?php

$image = "http://dev5.4loopdigital.co.za/wp-content/uploads/2015/06/servicesaccomm.jpg";  
$width = 960;
$height = 300;
echo '<a href="'.$image.'"><img src="'.$image.'" style=width:"' . $width . 'px;height:' . $height . 'px;"></a>';

?>
0
Derek On

Just add the image inside an anchor

echo '<a href="https://www.google.com"><img src="'.$image.'" style=width:"' . $width . 'px;height:' . $height . 'px;"></a>';