Title: get_background_image
Published: April 25, 2014
Last modified: August 20, 2026

---

# get_background_image(): string

## In this article

 * [Return](https://developer.wordpress.org/reference/functions/get_background_image/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_background_image/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_background_image/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_background_image/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_background_image/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_background_image/?output_format=md#wp--skip-link--target)

Retrieves background image for custom background.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_background_image/?output_format=md#return)󠁿

 string

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_background_image/?output_format=md#source)󠁿

    ```php
    function get_background_image() {
    	return get_theme_mod( 'background_image', get_theme_support( 'custom-background', 'default-image' ) );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/theme.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/theme.php#L1840)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/theme.php#L1840-L1842)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_background_image/?output_format=md#related)󠁿

| Uses | Description | 
| [get_theme_support()](https://developer.wordpress.org/reference/functions/get_theme_support/)`wp-includes/theme.php` |

Gets the theme support arguments passed when registering that support.

  | 
| [get_theme_mod()](https://developer.wordpress.org/reference/functions/get_theme_mod/)`wp-includes/theme.php` |

Retrieves theme modification value for the active theme.

  |

| Used by | Description | 
| [get_media_states()](https://developer.wordpress.org/reference/functions/get_media_states/)`wp-admin/includes/template.php` |

Retrieves an array of media states from an attachment.

  | 
| [Custom_Background::admin_page()](https://developer.wordpress.org/reference/classes/custom_background/admin_page/)`wp-admin/includes/class-custom-background.php` |

Displays the custom background page.

  | 
| [background_image()](https://developer.wordpress.org/reference/functions/background_image/)`wp-includes/theme.php` |

Displays background image path.

  | 
| [_custom_background_cb()](https://developer.wordpress.org/reference/functions/_custom_background_cb/)`wp-includes/theme.php` |

Default custom background callback.

  | 
| [_delete_attachment_theme_mod()](https://developer.wordpress.org/reference/functions/_delete_attachment_theme_mod/)`wp-includes/theme.php` |

Checks an attachment being deleted to see if it’s a header or background image.

  | 
| [get_body_class()](https://developer.wordpress.org/reference/functions/get_body_class/)`wp-includes/post-template.php` |

Retrieves an array of the class names for the body element.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/get_background_image/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_background_image/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_background_image/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_background_image/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/get_background_image/?output_format=md#comment-content-1259)
 2.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_background_image/#comment-1259)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_background_image%2F%23comment-1259)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_background_image%2F%23comment-1259)
 4. **Use Theme Background Image as Fallback if No Featured Image Exists**
 5. This example could be used to detect whether the current Page/Post has a Featured
    Image set – if so, it will use the Featured Image as the page background, if not
    it will use the current active theme’s default background image. As is, this should
    be used in the of the page template, just after the call to [wp_head()](https://developer.wordpress.org/reference/functions/wp_head/):
 6.     ```php
        // Declare $post global if used outside of the loop.
        $post = get_post();
    
        // check to see if the theme supports Featured Images, and one is set
        if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) ) {
    
            // Specify desired image size in place of 'full'.
            $page_bg_image     = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
            $page_bg_image_url = $page_bg_image[0]; // This returns just the URL of the image.
    
        } else {
            // The fallback – our current active theme's default bg image.
            $page_bg_image_url = get_background_image();
        }
    
        // And below, spit out the <style> tag... ?>
        <style type="text/css" id="custom-background-css-override">
            body.custom-background { background-image: url('<?php echo $page_bg_image_url; ?>'); }
        </style>
        ```
    
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_background_image%2F%3Freplytocom%3D1259%23feedback-editor-1259)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_background_image%2F)
before being able to contribute a note or feedback.