i am pretty new to sage and wonder if there are any guidelines for using images in template and css files.
for template files, there seems to be two ways:
First method (the classic wp way)
<img src="<?= get_template_directory_uri();
?>/assets/images/logo.png" alt="<?= get_bloginfo("name"); ?>"/>
Second method (sage style?!)
<img src="<?= Assets\asset_path('images/logo.png ') ?>"
alt="<?= get_bloginfo("name"); ?>"/>
which one should i prefer? with 2nd method images are expected to be in /dist/ folder.
for css/less files i did not find any way to use images (file not found?!). nothing of these work:
background: url("../images/logo.png") no-repeat;
background: url("images/logo.png") no-repeat;
background: url("assets/images/logo.png") no-repeat;
background: url("dist/images/logo.png") no-repeat;
canât find any help here in existing threads or in the docs
2 Likes
The first way, âclassicâ, should still point to dist
.
background: url("../images/logo.png") no-repeat;
should work in CSS.
4 Likes
You could also define absolute links using a base-url. That works pretty good, but I donât use autmated deploys (yet), so there might be an issue there. Not sure.
Yeah, absolute URLâs are tricky in CSS
background: url("../images/logo.png") no-repeat;
just be sure to run the âimagesâ gulp task beforehand so that the image is actually in dist/imagesâŚ
Anyone experiencing weirdness on how these relative urls are compiled? I keep getting the wrong path â for example, this:
background: url("../images/logo.png");
Is being output in CSS as:
background: url("styles/styles/images/logo.png");
Anyone else experience this ever?
1 Like
Yeah, itâs an issue with the minifer. Apply this PR: https://github.com/roots/sage/pull/1452
1 Like
@kalenjohnson thanks so much! Perfect fix