Is it possible to get a background image in CSS like you normally do in HTML when working with WordPress. I've tried doing this but it doesn't work.
background-image: url("<?php bloginfo('template_directory'); ?>/images/parallax_image.jpg ");
Is it possible to get a background image in CSS like you normally do in HTML when working with WordPress. I've tried doing this but it doesn't work.
background-image: url("<?php bloginfo('template_directory'); ?>/images/parallax_image.jpg ");
Another way is accessing image using css file location as the reference point, e.g. .class-name{ background-image:url("../images/file-name"); //one level up, then images folder background-image:url("../../images-directory-02/images/file-name"); //two levels up, then two folders in }
you can't add php code into .css files. but if you wanna do this using php see this.
I was having this issue with adding a background image to my Underscores based theme and I found this works:
I first tried:
but that didn't work for me.
You don't need to use PHP in this question, your CSS file is already in template folder, so you can call image just like this:
So you don't need to know template path to call images from your theme.
If the image folder is in the theme folder you can use:
Short answer is you can not render PHP in a CSS file. I would suggest making sure your
<rel>
tag is setup correctly and just using the/images/parralax_iamge.jpg
part.