WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use the_post_thumbnail featured image as the background image to a div container within a page template file.

I'm using LESS CSS and wondered if it was possible to pass in a Wordpress tag to the LESS file or use PHP in anyway?

If not, I guess my only option would be inline style?

share|improve this question

closed as off-topic by Mark Kaplun, Pieter Goosen, Howdy_McGee, s_ha_dum Dec 31 '15 at 17:06

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

    
To use a PHP function in a stylesheet you have to create the stylesheet with PHP-- for example, WordPress does this with load-styles.php on the backend--, or configure your server to process .css files as if they were PHP. See: stackoverflow.com/questions/8136331/… At any rate, this doesn't look WordPress specific to me. – s_ha_dum Sep 20 '13 at 14:59
    
Posted it here incase someone was able to come up with a Wordpress specific way of using featured image as background image in CSS. Thanks. – zigojacko Sep 20 '13 at 15:05
    
WordPress can't escape the basic rules of PHP, HTML/CSS, and HTTP :) – s_ha_dum Sep 20 '13 at 15:10
up vote 2 down vote accepted

There's nothing wrong with an inline style in this case - just set all your other rules in your LESS (like background position, repeat, size), and then in your template:

<div class="something"<?php

if ( $id = get_post_thumbnail_id() ) {
    if ( $src = wp_get_attachment_url( $id ) )
        printf( ' style="background-image: url(%s);"', $src );
}

?>>
share|improve this answer

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