I am trying to figure out why my image won't add to the WordPress website I am creating. This course came with other images that will display but not the ones I add as a jpg file. I am not sure why it will add the other jpg images but not the ones I want. Here's my code:
<?php get_header(); ?>
<div >
<div style="background-image: url(<?php echo
get_theme_file_uri('images/traffic.jpg') ?>)"></div>
<div >
<h1 >TBS</h1>
<h2 >Working to make traffic safer</h2>
<h3 >Explore constructing, utlities, and other types of work we do</h3>
<a href="#" >Service & Support</a>
<a href="#" >Signs</a>
<a href="#" >Utilities</a>
</div>
</div>
I am not sure if I need to add more information to this.
CodePudding user response:
Try this:
<div >
<div style="background-image: url(<?php echo
get_theme_file_uri('images/traffic.jpg'); height:200px;width:100% ?>)"></div>
<div >
<h1 >TBS</h1>
<h2 >Working to make traffic safer</h2>
<h3 >Explore constructing, utlities, and other types of work we do</h3>
<a href="#" >Service & Support</a>
<a href="#" >Signs</a>
<a href="#" >Utilities</a>
</div>
</div>
Problem is that you are closing <div>
tag without adding any content in that:
<div style="background-image: url(<?php echo
get_theme_file_uri('images/traffic.jpg') ?>);"></div>
So I have added height and width for showing the background image. Either you can add some content or specify the height and width of that div.
CodePudding user response:
I figured it out. I added the image to my image folder but it wasn't refreshed in VS editor. If you add images to a folder, make sure to refresh the image folder.