Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am stuck at add_custom_background.

I can change background color/image but I only want to change my index page. Currently, the changes apply on the whole page.

I want to make the changes from WP-admin.

How can I specify it to a specific page ?

Edit:

I just checked im running 3.3.1. So my version is not supported to use add_theme_support( 'custom-background' );

instead I want to use add_custom_background.

  if ( is_front_page() )
{
   add_custom_background();
}

Cant get it to work.

share|improve this question
    
That is what it's supposed to do. For what you want, you'll have to "hack" the theme to do that and then add custom options in the admin. –  Miha Rekar Oct 8 '12 at 11:36
    
So what do you suggest that i do in this case ? Is there any other plugin i could use ? –  M3o Oct 8 '12 at 12:21
    
As I said - "hack" the theme. I almost never trust plugins, so I would write it myself, but yeah, there could be a plugin for that :P –  Miha Rekar Oct 8 '12 at 12:22
    
any suggestion ? :P –  M3o Oct 17 '12 at 11:48
add comment

2 Answers

up vote 2 down vote accepted

You can check in your callback function if you are an the front page.

Sample code for the theme’s functions.php:

add_action( 'after_setup_theme', 'wpse_67480_theme_setup' );

function wpse_67480_theme_setup()
{
    $bg_options = array (
        'wp-head-callback' => 'wpse_67480_background_frontend',
        'default-color'    => 'f0f0f0',
        'default-image'    => '',
    );
    add_theme_support( 'custom-background', $bg_options );

    add_theme_support(
        'custom-header',
        array (
            'width'       => 960,
            'height'      => 200,
            'flex-height' => TRUE,
            'flex-width'  => TRUE,
            'header-text' => FALSE,
            'wp-head-callback' => 'wpse_67480_header_frontend',
        )
    );
}

wpse_67480_background_frontend()
{
    if ( is_front_page() )
    {
        _custom_background_cb();
    }
}

wpse_67480_header_frontend()
{
    if ( ! is_front_page() )
    {
        return;
    }

    // create your header code here
}
share|improve this answer
    
Im using wordpress 3.2 i think and that code sample you pasted is supported by 3.4.0 and above ( add_theme_support( 'custom-background'). I have to use add_custom_background since im not on that update. Thanks for the fast reply btw. –  M3o Oct 8 '12 at 14:15
1  
Please run the update. 3.2 has some unfixed security issues. The solution – check for is_front_page() in the callback – is the same there, just the registration is different. –  toscho Oct 8 '12 at 14:17
    
I just checked im running 3.3.1. The only reason i havent updated yet is because i have over 30+ wp sites ( mobile sites ) and im really doubtful if it would ruin something or ruin any plugin. –  M3o Oct 8 '12 at 14:21
add comment

You can use the body class and define your background in your style.css

Example: background for frontpage:

body.home { background: #eee; } 

background for pages

body.page { background: #ccc; }

background for archive pages

body.archive { background ... }

and so on. Just check your source code for the body class of the site you want to address.

If your background is for another element but body you can add the body class in front of it:

body.home .wrapper { background ... }
share|improve this answer
    
Thank for the answer , but what i wanna do is to make the admin of the site change his index page from wp-admin –  M3o Oct 17 '12 at 13:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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