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...
In the file functions.php
I made 3 changes :
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'; }*/ ... }
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);
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.
background-image
property on the section in question?