Different codes for main page and single posts (2 posts)

  1. lelymarques
    Posted 5 years ago #


    Is there a css / php code that makes possible showing a background image on the main page of my blog and another different background on single pages?

    I've heard it's possible and it's not difficult.

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    Something like:

    <?php if( is_home() || is_front_page() ) $backround_image = 'image1.jpg';
    else $backround_image = 'image2.jpg';
    $bg = get_bloginfo('template_directory'); ?>
    <style type = "text/css">
    body{background-image:url(<?php echo get_bloginfo('stylesheet_directory') .' /images/' . $backround_image;?>}

    in the <head></head> section of your theme's header.php template file should work. It assumes that the two images will be present in your theme's images folder.

Topic Closed

This topic has been closed to new replies.

About this Topic