WP_Theme::get_screenshot()publicWP 3.4.0

Returns the main screenshot file for the theme.

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.)

Метод класса: WP_Theme{}

Хуков нет.

Возвращает

Строку|false. Screenshot file. False if the theme does not have a screenshot.

Использование

$WP_Theme = new WP_Theme();
$WP_Theme->get_screenshot( $uri );
$uri(строка)
Type of URL to return, either 'relative' or an absolute URI.
По умолчанию: absolute URI

Список изменений

С версии 3.4.0 Введена.

Код WP_Theme::get_screenshot() WP 6.5.2

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;
}