Using the customizer, add this piece of code in your functions.php
add_action( 'customize_register' , 'my_theme_options' );
function my_theme_options( $wp_customize ) {
$wp_customize->add_section('mytheme_section_bg_img', array(
'title' => __( 'Section name', 'my_theme_slug' ),
'priority' => 100,
'capability' => 'edit_theme_options',
'description' => __('Select a background image', 'my_theme_slug'),
)
);
$wp_customize->add_setting('section_bg_img');
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'section_bg_img', array(
'label' => __( 'Background image', 'my_theme_slug' ),
'section' => 'mytheme_section_bg_img',
'settings' => 'section_bg_img',
'priority' => 10,
)
));
}
You must change "my_theme_slug" by your theme slug.
Once done, you must select an image from the customizer, and finally print it wherever you want using this code:
<div<?php
if ( $section_bg_img = get_theme_mod( 'section_bg_img' ) )
echo ' style="background-image: url(' . $section_bg_img . ');"';
?>></div>
Hope it helps!