Search code examples
phphtmlwordpresswordpress-theming

How to add php into inline style background-image Wordpress


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


Solution

  • 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');">