Title: CSS background image from PHP file
Last modified: March 15, 2017

---

# CSS background image from PHP file

 *  [Thomasso75](https://wordpress.org/support/users/thomasso75/)
 * (@thomasso75)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/css-background-image-from-php-file/)
 * I’m trying to set a background in CSS using a PHP file like background: url(‘
   images/header-pics/display_header-pics.php’) no-repeat;
 * It works when I use:
 * <?php
    $img = “3.png”; header (‘content-type: image/png’); readfile($img); ?>
 * But if I add a conditional statement nothing is returned. My code is:
 * <?php
    if(is_single() || is_archive()) { $imagePath = “3.png”; } elseif(is_home()){
   $imagePath = “2.png”; } else { $imagePath = “1.png”; }
 *  header (‘content-type: image/png’);
    readfile($imagePath); ?>

The topic ‘CSS background image from PHP file’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 0 replies
 * 1 participant
 * Last reply from: [Thomasso75](https://wordpress.org/support/users/thomasso75/)
 * Last activity: [9 years, 2 months ago](https://wordpress.org/support/topic/css-background-image-from-php-file/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
