I want to have featured image on specific div on home page that could be changed in customizer. I saw in documentation custom background for body(https://codex.wordpress.org/Custom_Backgrounds) But I want to make it for specific div eg. #featured-home-image. How?

$args = array(
    'default-color' => '000000',
    'default-image' => '%1$s/images/background.jpg',
add_theme_support( 'custom-background', $args );

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() {

    _custom_background_cb(); // Default handler

    $style = ob_get_clean();
    $style = str_replace( 'body.custom-background', '#featured-home-image', $style );

    echo $style;
| improve this answer | |

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.