Hardik Shah
Hardik Shah

Reputation: 161

Image tag src attribute not working in wordpress

I am creating a Google chart in wordpress, chart is rendered and stored into an image. However I am not able to call the image using <img src="" />. Following is the code:

$filepath = "/wp-content/uploads/graph.png";

file_put_contents($filepath, $response);

echo $filepath;

echo "<img src=\"/wp-content/uploads/graph.png\">";

I have also tried with http://*/graph.png which is not working. If I open the same in different browser, image is showing properly.

Upvotes: 0

Views: 1984

Answers (2)

maestrom4
maestrom4

Reputation: 21

Try this

echo '<img src="' . get_bloginfo('template_directory') . '/images/logo.gif" />';

Go for 'template_directory' or 'stylesheet_directory'.

Upvotes: 1

Philip F
Philip F

Reputation: 86

You may try the below code;

Much better if you combine your HTML code and PHP code. Much cleaner easy to read.

PHP code

<?php
    Try changing your file path to
    $filepath = "../../wp-content/uploads/graph.png";
    file_put_contents($filepath, $response);
?>

HTML Code

<img src="<?php echo $filepath; ?>"/>

Upvotes: 0

Related Questions