Title: WP_Theme::get_screenshot
Published: April 25, 2014
Last modified: May 20, 2026

---

# WP_Theme::get_screenshot( string $uri = 'uri' ): string|false

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_theme/get_screenshot/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_theme/get_screenshot/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_theme/get_screenshot/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_theme/get_screenshot/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_theme/get_screenshot/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_theme/get_screenshot/?output_format=md#changelog)

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

Returns the main screenshot file for the theme.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_theme/get_screenshot/?output_format=md#description)󠁿

The main screenshot is called screenshot.png. gif and jpg extensions are also allowed.

Screenshots for a theme must be in the stylesheet directory. (In the case of child
themes, parent theme screenshots are not inherited.)

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_theme/get_screenshot/?output_format=md#parameters)󠁿

 `$uri`stringoptional

Type of URL to return, either `'relative'` or an absolute URI. Defaults to absolute
URI.

Default:`'uri'`

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

 string|false Screenshot file. False if the theme does not have a screenshot.

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

    ```php
    public function get_screenshot( $uri = 'uri' ) {
    	$screenshot = $this->cache_get( 'screenshot' );
    	if ( $screenshot ) {
    		if ( 'relative' === $uri ) {
    			return $screenshot;
    		}
    		return $this->get_stylesheet_directory_uri() . '/' . $screenshot;
    	} elseif ( 0 === $screenshot ) {
    		return false;
    	}

    	foreach ( array( 'png', 'gif', 'jpg', 'jpeg', 'webp', 'avif' ) as $ext ) {
    		if ( file_exists( $this->get_stylesheet_directory() . "/screenshot.$ext" ) ) {
    			$this->cache_add( 'screenshot', 'screenshot.' . $ext );
    			if ( 'relative' === $uri ) {
    				return 'screenshot.' . $ext;
    			}
    			return $this->get_stylesheet_directory_uri() . '/' . 'screenshot.' . $ext;
    		}
    	}

    	$this->cache_add( 'screenshot', 0 );
    	return false;
    }
    ```

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

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

| Uses | Description | 
| [WP_Theme::get_stylesheet_directory_uri()](https://developer.wordpress.org/reference/classes/wp_theme/get_stylesheet_directory_uri/)`wp-includes/class-wp-theme.php` |

Returns the URL to the directory of a theme’s “stylesheet” files.

  | 
| [WP_Theme::get_stylesheet_directory()](https://developer.wordpress.org/reference/classes/wp_theme/get_stylesheet_directory/)`wp-includes/class-wp-theme.php` |

Returns the absolute path to the directory of a theme’s “stylesheet” files.

  | 
| [WP_Theme::cache_get()](https://developer.wordpress.org/reference/classes/wp_theme/cache_get/)`wp-includes/class-wp-theme.php` |

Gets theme data from cache.

  | 
| [WP_Theme::cache_add()](https://developer.wordpress.org/reference/classes/wp_theme/cache_add/)`wp-includes/class-wp-theme.php` |

Adds theme data to cache.

  |

| Used by | Description | 
| [WP_Theme::__get()](https://developer.wordpress.org/reference/classes/wp_theme/__get/)`wp-includes/class-wp-theme.php` |

__get() magic method for properties formerly returned by [current_theme_info()](https://developer.wordpress.org/reference/functions/current_theme_info/)

  | 
| [WP_Theme::offsetGet()](https://developer.wordpress.org/reference/classes/wp_theme/offsetget/)`wp-includes/class-wp-theme.php` |

Method to implement ArrayAccess for keys formerly returned by [get_themes()](https://developer.wordpress.org/reference/functions/get_themes/) .

  |

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

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

## User Contributed Notes

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