Background image not showing in my WP theme

I am building my first WordPress theme and the background image is not showing.

This is the code I use to display the background image:

   <style>
        .showcase {
            background:url (<?php echo get_theme_mod('showcase_image', get_bloginfo('template_url').'/showcase.jpg'); ?>);
        }
    </style>

I got an error using developers’ tools when inspecting the background image. The error is “invalid property value”.

invalid property error background

When I change the value of .showcase to “blue” it works. The issue as the error message says is with the value url (http://…). Until now I could not figure how to fix it.

Besides, the image link generated by the php code work fine I copy it to the browser.

I will appreciate your help

Hello.

Take out the space between the url call, and its argument. Also, just for clarity, use background-image

.showcase {
            background-image: url(<?php echo get_theme_mod('showcase_image', get_bloginfo('template_url').'/showcase.jpg'); ?>);
        }

Explaination: background & background-image accept multiple values. So, by introducing a space between the keyword url and the value, the compiler assumes you have input two backgrounds, and neither is valid.

I hope this helps

1 Like