Add custom background to section in home page

To be clear : in WordPress there is an option to change the body backgroung-image. I want to modify this option to permit to change the background-image of a particular section (named #section1) and not the background-image of the body.

I know that this question has already been asked by Emir Dupovac, but I applied the advices given by TheDeadMedic and it just doesn’t work…

Link to the similar question

In the file functions.php I made 3 changes :

  1. I commented the part of the default code relating to the display of the background-image

    function espace_harmonie_body_classes( $classes ) {
    // Adds a class of custom-background-image to sites with a custom background image.
    /*if ( get_background_image() ) {
    $classes[] = 'custom-background-image';
    }*/
    ...
    }
    
  2. I put this code in my <template_name>_setup() function :

    // Image in section  
    $defaults = array(
        'default-color'    => 'ff0000',
        'default-image'    => '%1$s/images/image-section.jpg',
        'default-repeat'         => '',
        'default-position-x'     => '',
        'default-attachment'     => '',
        'wp-head-callback' => 'wpse_189361_custom_background_cb',
        'admin-head-callback'    => '',
        'admin-preview-callback' => ''
    );
    add_theme_support( 'custom-background', $default);
    
  3. And this one just after the <template_name>_setup() function :

    function wpse_189361_custom_background_cb() {
        ob_start();
        _custom_background_cb(); // Default handler
        $style = ob_get_clean();
        $style = str_replace( 'body.custom-background', '#section1', $style );
        echo $style;
    }
    

Despite these modifications, when I try to add a background image in the admin interface, the background is applied to the body and not to my section. Could someone explain me why? Thank you.

Solutions Collecting From Web of "Add custom background to section in home page"

Okay! Finally I have found the solution! (even if I don’t understand why we have to do this that way).

In fact we have not to modify the function.php file but the customizer.php with the code I quoted above (in the question).

Now I really feel released from that issue, but anyone could explain me why is it that file that we have to modify? I think I haven’t really understood the role of the differents files.

The inc subdirectory

The inc subdirectory content

enter image description here