skip to Main Content

How to include image path to background-image in WordPress correctly? Cause this isn’t working for me

<div class="slide" style="background-image: url("<php bloginfo('template_url'); ?> /assets/img/slide1.jpg");">

Screen of code from inspector

2

Answers


  1. Are you sure u didn’t mess with your theme options? because that thing should just work. Check the documentation: https://developer.wordpress.org/reference/functions/bloginfo/

    It is noted to use get_template_directory_uri() instead for the parent template directory or get_stylesheet_directory_uri() for the child template directory

    Login or Signup to reply.
  2. You are trying it in a wrong way. Reference : Check Here

    Replace your code with:

    <div class="slide" style="background-image: url('<?php echo get_template_directory_uri(); ?>/assets/img/slide1.jpg');">
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search