WP_Theme::get_screenshot

Advertisement

Summery Summery

Returns the main screenshot file for the theme.

Syntax Syntax

WP_Theme::get_screenshot( string $uri = 'uri' )

Description 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 Parameters

$uri

(Optional) Type of URL to return, either 'relative' or an absolute URI. Defaults to absolute URI.

Default value: 'uri'

Return Return

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

Source Source

File: wp-includes/class-wp-theme.php

			}
			return $this->get_stylesheet_directory_uri() . '/' . $screenshot;
		} elseif ( 0 === $screenshot ) {
			return false;
		}

		foreach ( array( 'png', 'gif', 'jpg', 'jpeg' ) 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;
	}

	/**
	 * Return files in the theme's directory.
	 *
	 * @since 3.4.0

Advertisement

Changelog Changelog

Changelog
Version Description
3.4.0 Introduced.

Advertisement

Leave a Reply