Skip to content
Advertisement

How can I get my PHP code working inside img src in WordPress?

I’ve been trying to get a small image of an icon inside of my article thumbnail custom fields in WordPress website. But the image itself isn’t loading but the site understands that image is supposed to be there.

This is my PHP code right now

<?php 
$filepath= "<?php bloginfo('template_url'); ?>/img/downarrow.png";
$meta_value = get_post_meta( $post->ID, 'Magamistuba', true ); 
            if  (!empty( $meta_value )) {echo   '<img src="'.$filepath.'">'.$meta_value;}
            else {} 

?>

On this picture it shows how it appears in the console.

Here is how it is when i tryed

$filepath = bloginfo('template_url') ."/img/downarrow.png";

enter image description here

Advertisement

Answer

Try with this.

$filepath = get_template_directory_uri()."/img/downarrow.png";
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement