I’m using Local by Flywheel and my local URL is: http://sarasota-soccer-club.local/
. What I’m doing is adding a background image to a div
in WordPress: <?php echo get_site_url(); ?>/wp-content/uploads/2023/01/hero-image.jpg
. The thing is that the image sometimes doesn’t show. When this happens I just replace the get_site_url()
with the local URL and the background image comes back. I’m using PHPStorm and running NGINX on macOS Ventura. Any idea what’s going on? Thanks.
2
Answers
The actual problem is with your theme because sometime theme code conflict issue is happening.
Better to use get_template_directory_uri() intead of get_site_url().
For Reference visit https://developer.wordpress.org/reference/functions/get_site_url/
https://developer.wordpress.org/reference/functions/get_template_directory_uri/
When using image as a background, it should be located in your theme’s folder (since it’s part of the style) something like this:
"/wp-content/themes/your-theme/assets/img/hero-image.jpg"
If you use this approach, then you need to call it using this function:
get_template_directory_uri() (that will return the path of your theme’s location):
If you want to continue using your approach you can use:
or