Custom-background in home page only

I’m trying to have a custom background to be shown on the home page only using add_theme_support in functions file in WordPress.

add_theme_support( ‘custom-background’ ) works when used by itself, but I can’t get it to work in a condition. This is my code which includes echo statements for testing:

function custom_bg() {
   	echo "you are at front page"; 
        add_theme_support( 'custom-background' );
        echo "you are NOT at front page";
add_action( 'wp', 'custom_bg' );

The function seems to work, since the echo statements behave as expected. I’m hooking to ‘wp’ so that the function gets executed after wordpress knows that the page will be the front page. What am I missing or doing wrong?

In Reading Settings I have static page with the correct front page. I’m using a front-page.php template file. And I’m using underscores starter theme.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.