• 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.