WordPress.org

Support

Support » How-To and Troubleshooting » Theme customization for homepage background color

Theme customization for homepage background color

  • I’m using a theme which offers a custom option to create a background. The problem is that the background appears sitewide and we only want it for the homepage. I’m a little out of my element here and could use any sort of support anyone can give.

    The code as it appears now to retrieve the background image or color:
    <?php if($bg_image <> '') { ?>url(../images/uploads/<?php echo $bg_image; ?>) <?php echo $bg_repeat; ?><?php } ?> 0 <?php echo $bg_top_offset; ?>px #<?php echo $bg_color; ?>;

    I would like to modify this to query for the homepage first and echo $home_bg_image or $home_bg_color and perform the above code if those things aren’t present. Can anyone help me with this if statement since I know nothing about how to set this up?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Try using the is_home conditional tag, an example is at link (backup any files before editing)

    Thanks for the response. My problem is that I don’t know what the rest of that would look like. I tried several things, none of which worked. Can you frame something for me that I could build off of? The link you gave is helpful if you know how php syntax works which unfortunately I don’t.

    I guess was thinking something along the lines of: <?php if is_front_page() {0 <?php echo $bg_top_offset; ?>px #<?php echo $home_bg_color; } ?> else{<?php if($bg_image <> '') { ?>url(../images/uploads/<?php echo $bg_image; ?>) <?php echo $bg_repeat; ?><?php } ?> 0 <?php echo $bg_top_offset; ?>px #<?php echo $bg_color; ?>;

    Does that make sense? Or do I need an elseif? Thanks again for your help.

    You should just be able to add is_home along with the $bg_image check. So something like…

    <?php if ( $bg_image <> '' && is_home() ) { ?>

    should cover it

    Jarrett, thanks for the help. That seems like it might work but the problem I have is that I want to give the home page one color and the rest of the pages another color. How about throwing an else statement in there? I tried the following and it didn’t work. Ideas?

    <?php if($bg_image <> '' && is_home() ) { ?>url(../images/uploads/<?php echo $bg_image; ?>) <?php echo $bg_repeat; ?><?php } ?> 0 <?php echo $bg_top_offset; ?>px #666; else{<?php echo $bg_color; ?>} ;

    <?php if( $bg_image <> '' && is_home() ) { ?>
    url(../images/uploads/<?php echo $bg_image; ?>)
    <?php echo $bg_repeat; } ?> 0
    <?php echo $bg_top_offset; ?>px
    <?php if ( is_home() ) { '#666;' } else { echo '#' . $bg_color; } ?>

    Try that and let me know if it works for you.

    Nope, that breaks it.

    Define breaks it.

    Right, my bad. Here is the page with the code from my very first post, and here is the page with the last code that you gave me.

    Whoops, try an echo before ‘#666;’

    <?php if ( is_home() ) { echo '#666;'; } else { echo '#' . $bg_color; } ?>

    It seems that we are almost there. The code isn’t picking up the #666 though. The homepage still picks up whatever is assigned to $bg_color. As a random thought of ‘what if…?’, I tried changing the is_home to is_front_page and that didn’t work either.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Theme customization for homepage background color’ is closed to new replies.
Skip to toolbar