Images are displayed as background but not as img src

This is my first post, so please bear with me.

I am working on a WordPress site and was facing a problem with my images.

I have a background image in my stylesheet background-image: "images/dummybg.jpg"

and this works fine and displays

When I go to the index file and try the <img src="images/dummybg.jpg">

image is not displayed.

Both .css and index.php are free in my folder, so their relative paths MUST be the same. So my question is, why does one way work and not the other?

+3


source to share


2 answers


WordPress has a function to get to your image directory So from your index it would be:



<img src="<?php bloginfo('template_url'); ?>/images/dummybg.jpg">

      

+3


source


You used an image in css. it automatically gets the path to the image.

but if you used in any other file in the tag, you will need to put the entire image path in the src attribute.

you need to set the current theme path in the next wordpress function you get.



get_template_directory ();

if you need more information please visit wordpress features

I am sure this will work for you.

+1


source







All Articles