Display custom_background outside wp_head()

custom_background() places the CSS to wp_head() as you mentioned so to get those CSS as if you don’t have wp_head() in your header, these tweaks from the core files would help: function wpse_228588_background_image_css() { $background_styles=””; if ( $bgcolor = get_background_color() ) $background_styles .= ‘background-color: #’ . $bgcolor . ‘;’; $background_image_thumb = get_background_image(); if ( $background_image_thumb … Read more

Change background color with a dominant from picture

You can use a jQuery plugin called Color Thief. Files needed: jquery.js (is included in WordPress) quantize.js (download from color-thief github page) color-thief.js (download from color-thief github page) WordPress setup: Open functions.php (located in your theme’s folder) and add the code below to load the files in WordPress. In this case I placed all files … Read more

Add custom background to div in home page

Use the wp-head-callback argument to specify your own handler: add_theme_support( ‘custom-background’, array( ‘wp-head-callback’ => ‘wpse_189361_custom_background_cb’, ‘default-color’ => ‘000000’, ‘default-image’ => ‘%1$s/images/background.jpg’, )); function wpse_189361_custom_background_cb() { ob_start(); _custom_background_cb(); // Default handler $style = ob_get_clean(); $style = str_replace( ‘body.custom-background’, ‘#featured-home-image’, $style ); echo $style; }

How to get attachment id of background image?

Query for post meta keys _wp_attachment_is_custom_background or _wp_attachment_is_custom_background: function t5_bg_img_id() { if ( ! $bg_img = get_background_image() ) return FALSE; $query = array( ‘post_type’ => ‘attachment’, ‘fields’ => ‘ids’, ‘meta_query’ => array ( array ( ‘key’ => ‘_wp_attachment_is_custom_background’, ‘value’ => get_option( ‘stylesheet’ ), ‘compare’ => ‘==’, ), array ( ‘key’ => ‘_wp_attachment_metadata’, ‘value’ => basename( … Read more

How WP_Customize_Background_Image_Control is supposed to work?

There’s very little documentation on this class, but here below is the full example from WordPress core (here’s github). Note you’d be using the $wp_customize object you get as argument to your custom_register callback and not $this as does the core class. I’ve done a search and replace below and it works. /* CORE COPY … Read more

How do I add settings to the Background Options Page?

The page content for custom backgrounds is created in wp-admin/custom-background.php. There is no action available where the fields are printed. To add new fields we have to print JavaScript into the page footer. The action is ‘admin_footer-appearance_page_custom-background’. To save those field values we have to hook into ‘load-appearance_page_custom-background’. The following example adds a new option … Read more

featured image as background image on pages

You need to echo the return value from wp_get_attachment_image_src(). It also returns an Array(), so you need to grab the needed part from that array. In this case it’s the first/0 value. Example: <?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘full’ );?> <div id=”post” class=”your-class” style=”background-image: url(‘<?php echo $thumb[‘0′];?>’)”> <p>your text demo</p> </div>