I am a theme author and the theme I made is used in a multisite environment. I have added the custom_background feature to this theme, with a default image and everything works as expected : the user can change the image and see the result live is the Theme Customizer before putting it online.

Here is the custom_background declaration:

add_action('after_setup_theme', 'user83643_theme_features');
function user83643_theme_features(){
    add_theme_support( 'custom-background' , array(
        'default-color' => '1878A0',
        'default-image' => get_template_directory_uri() . '/img/default.jpg',
        'wp-head-callback' => '__return_false',

However, when a fresh new site is created in the network, the default image does not appear in the frontend. I can see it in the backend in the theme customizer, but I have to save it once to activate it on the frontend : get_theme_mod('background_image') returns false before I save it once.

Any idea how to save the default image (and color) in the database upon the first theme activation ?


I assume you mean "get_theme_mod('background_image') returns false" before I "save it once to activate it"

If that is the case, get_theme_mod accepts a default parameter. Check the Codex:

$name (string) (required) Theme modification name.

    Default: None 

$default (boolean|string) (optional)

    Default: false

Pass your default image as the second parameter to that function and you should be set.

  • I have edited my question following your recommendations to make it clearer. – Fabien Quatravaux Mar 8 '13 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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