In this scenario, the tag that you want to call to execute your function is the wp_head()
.
Looking at the code you provides, you have the idea down, but I decided to rewrite it differently. In your child theme’s functions.php
file, add the following:
add_action( 'wp_head', 'wpse_238911_weekly_background' );
function wpse_238911_weekly_background() {
$day = date( "l" );
switch( $day ) {
case 'Monday':
$background_image="mon-img.jpg";
break;
case 'Tuesday':
$background_image="tue-img.jpg";
break;
case 'Wednesday':
$background_image="wed-img.jpg";
break;
case 'Thursday':
$background_image="thu-img.jpg";
break;
case 'Friday':
$background_image="fri-img.jpg";
break;
case 'Saturday':
$background_image="sat-img.jpg";
break;
case 'Sunday':
default:
$background_image="sun-img.jpg";
break;
}
?>
<style type="text/css">
body {
background-image: url( 'http://web.site/img/<?php echo $background_image; ?>' );
}
</style>
<?php
}
Just switch out the mon-img.jpg
to your actual image names and change the http://web.site/img/
path to wherever you will be having your day-of-the-week images stored.