I have the following code in my WordPress site
HTML
<div class="test">
<?php if(has_category( 'update' ) || has_category( 'uncategorized' )) { ?>
<img alt="icn" src="<?php bloginfo('template_directory'); ?>/img/logo.png">
<?php } elseif(has_category( 'event' )) { ?>
<img alt="icn" src="<?php bloginfo('template_directory'); ?>/img/logo.png">
<?php } ?>
</div>
This puts an image in the place of the category name. (category name ‘update’ = logo.png)
My issue is that I want their sizes responsive since they are going to be put overtop a responsive height div. My idea is to turn them into the background image of the ‘test’ div. I can’t seem to rewrite the img tag code to put them as background images of a div instead of just putting the image itself.
EDIT ex.
<?php if(has_category( 'update' ) || has_category( 'uncategorized' )) { ?>
<div style="background-image:url('...');">
...
Have you tried something like this:
Or, to make it a little cleaner:
Realize that if there is nothing inside of the
.bg-image
div, you’ll need to add some CSS to make it “visible”: a height and width at minimum.Also, instead of
get_bloginfo('template_directory')
, consider usingget_template_directory_uri()
.