Reputation: 2181
I am trying to use a background image in one of my Sage template files.
However when I try this the image is not being displayed.
<section class="banner" style="background-image: url(../images/banner.jpg);">
The banner.jpg
file is located in theme-name/assets/images/banner.jpg
What am I doing wrong here?
Upvotes: 1
Views: 3331
Reputation: 124
The previous answers use some of WordPress' built-in functions for resolving a path to the current theme. However, in Sage (using Blade templates) this is handled with the @asset
directive:
<section class="banner" style="background-image: url("@asset('images/example.jpg')");">
Upvotes: 1
Reputation: 408
Try this in your header.php:
<section class="banner" style="background-image: url(wp-content/themes/theme-name/dist/images/about-us-top-side.png);">
or
<section class="banner" style="background-image: url(wp-content/themes/theme-name/assets/images/about-us-top-side.png);">
The first one will have the optimized image if you are using the Sage theme properly.
Upvotes: 0
Reputation: 4148
Replace your code with below code. You need to add assets
before image folder because as per your image path you mention images folder is sub folder of assets
<section class="banner" style="background-image: url('../assets/images/banner.jpg');">
Used
get_template_directory_uri()
. It Retrieve theme directory URI.
<section class="banner" style="background-image: url('<?php echo get_template_directory_uri(); ?>/assets/images/banner.jpg');">
Used
get_stylesheet_directory_uri()
if you used child theme .It return URI for the current theme/child theme
<section class="banner" style="background-image: url('<?php echo get_stylesheet_directory_uri(); ?>/assets/images/banner.jpg');">
Upvotes: 1
Reputation: 25
Try this:
<section class="banner" style="background-image: url(/wp-content/themes/theme-name/assets/banner.jpg);">
or this:
<section class="banner" style="background-image: url('<?php echo get_template_directory_uri(); ?>/assets/images/banner.jpg');">
or maybe you just forgot "assets":
<section class="banner" style="background-image: url('../assets/images/banner.jpg');">
Upvotes: 0
Reputation: 61
Please use wordpress template directory path
<section class="banner" style="background-image: url(<?php echo get_template_directory(); ?>/images/banner.jpg);">
Upvotes: 0