How to set a default background

Community Forums Forums Design Tips and Tricks How to set a default background

This topic is: not resolved

This topic contains 2 replies, has 2 voices, and was last updated by  andym119 4 months, 3 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #92965

    andym119
    Member
    Post count: 72

    I run a multisite and I would like to set a default background for each theme.

    If I set the default background in the css, users cant’t overwrite it in admin > appearance > background

    Is there a code snippet for adding a default background or background-image in my functions.php child themes.

    Any help would be much appreciated, thanks

    #93133

    Davinder Singh Kainth
    Participant
    Post count: 1197
    #93379

    andym119
    Member
    Post count: 72

    Hi Davinder, thanks for the reply.

    Yes I have tried that as well as things like:

    
    $defaults = array(
    	'default-color'          => '000000',
    	'default-image'          => '',
    	'default-repeat'         => '',
    	'default-position-x'     => '',
    	'wp-head-callback'       => '',
    	'admin-head-callback'    => '',
    	'admin-preview-callback' => ''
    );
    add_theme_support( 'custom-background', $defaults );
    
    
    $args = array(
    	'default-color' => '000000',
    	'default-image' => get_template_directory_uri() . '/images/background.jpg',
    );
    add_theme_support( 'custom-background', $args );
    

    But that only sets the background ready in appearance > background, users have to click save for it to take affect on the front end.

    This works on the front end by default, by using css in the functions.php but again, users can’t overwrite it in appearance > background:

    
    add_custom_background('set_theme_background');
    function set_theme_background() {
    	echo "<style type='text/css'>";	 
    		echo "body { background-color: #000000;}";
    	echo "</style>";
    }

    Is there a way of putting a conditional to the above code so it applies the above only if there is no background set in appearance > background.

    Thanks in advance

    • This reply was modified 4 months, 3 weeks ago by  andym119.
    • This reply was modified 4 months, 3 weeks ago by  andym119.
    • This reply was modified 4 months, 3 weeks ago by  andym119.
    • This reply was modified 4 months, 3 weeks ago by  andym119.
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.