X

Use the Custom Backgrounds theme feature

Custom backgrounds have been around for a while, but the add_theme_support() function has been around since WordPress 3.4. The cool thing about using this feature for your themes is that it will give users the ability to change the custom background screen in the administrator's Appearance menu. When using it, you must also make sure you have added the body_class() and wp_head() template tags correctly to provide feature compatibility. Then, add this code to the functions.php file of your WordPress theme, and you are all set. I've included a second snippet so you can see what arguments are available for the add_theme_support() function. You may also want to check out the WordPress codex for even more information.


Code Snippet:


$args = array(
'default-color' => '000000',
'default-image' => get_template_directory_uri() . '/images/background.png',
);
add_theme_support('custom-background',$args);


Code Snippet:


$defaults = array(
'default-color' => '',
'default-image' => '',
'default-repeat' => '',
'default-position-x' => '',
'default-attachment' => '',
'wp-head-callback' => '_custom_background_cb',
'admin-head-callback' => '',
'admin-preview-callback' => ''
);
add_theme_support( 'custom-background', $defaults );

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!