Npm run build:production renames images - Displaying Image in Theme File

How can I display an image in the theme files? The problem with using something like:

<img src="<?= get_template_directory_uri(); ?>/assets/images/logo.png" />

Is that logo.png gets renamed during the build process with a random number attached, meaning it 404s

Any suggestions? I’d have expected some sort of helper function if this was the case but I can’t see one

Thanks

I’m about to update the Sage 9 docs with this info, but try:

<img src="<?= App\asset_path('images/logo.png'); ?>">

1 Like

Great that works, thanks!

Hello,

What about the images called on css files usign background-image?

Thank you

@SebConejo: bud (bud-alias) can also resolve those URLs comfortably, see

Example for resolving assets in SASS (using bud):
https://discourse.roots.io/t/tip-bud-alias-bud-alias-in-scss-sass/24208

You know how there’s a big warning that pops up when you bump an old thread?

Don’t do that. This topic was six years old and already solved