The page.tpl.php prints the header image like so. I need to change it so that it prints it as a background image. i.e <div style="background-image:"' . $url . '"></div> When I make that change the value of $url changes and includes additional text, not just the path to the image as it does in this format. How can I change this?

if ($node->field_header_image && $node->field_header_image['und'][0]['uri']) {
        $url = file_create_url($node->field_header_image['und'][0]['uri']);
        echo '<img src="' . $url . '" width="100%">';

1 Answer 1


You are retrieving the absolute url of the file correctly, but your quotes in style attribute are a little mixed up.

Try this:

print '<div style="background-image:url(' . $url . ');"></div>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.