Home > Back-end >  How to add php into inline style background-image Wordpress
How to add php into inline style background-image Wordpress

Time:10-11

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

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

Screen of code from inspector

CodePudding user response:

You are trying it in a wrong way. Reference : Check Here

Replace your code with:

<div  style="background-image: url('<?php echo get_template_directory_uri(); ?>/assets/img/slide1.jpg');">

CodePudding user response:

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

  • Related