Timber Logo

You are reading the documentation for Timber v2.x. Switch to the documentation for Timber v1.x.

Timber\​Theme

Need to display info about your theme? Well you've come to the right place. By default info on the current theme comes for free with what's fetched by Timber::context() in which case you can access it your theme like so:

PHP

<?php
$context = Timber::context();

Timber::render('index.twig', $context);
?>

Twig

<script src="{{ theme.link }}/static/js/all.js"></script>

HTML

<script src="http://example.org/wp-content/themes/my-theme/static/js/all.js"></script>

Overview #

This class extends Timber\Core
This class implements JsonSerializable

Properties #

NameTypeDescription
$namestringthe human-friendly name of the theme (ex: My Timber Starter Theme)
$versionstringthe version of the theme (ex: 1.2.3)
$parent\Timber\Themethe Timber\Theme object for the parent theme
$parent_slugstringthe slug of the parent theme (ex: _s)
$slugstringthe slug of the theme (ex: my-timber-theme)
$uristringRetrieves template directory URI for the active (parent) theme. (ex: http://example.org/wp-content/themes/my-timber-theme).

Methods #

NameReturn TypeSummary/Returns
__construct()Constructs a new Timber\Theme object.
display()false or stringGets a theme header, formatted and translated for display.
get()false or stringGets a raw, unformatted theme header.

Returns: String on success, false on failure.
link()string

Returns: Retrieves template directory URI for the active (child) theme. (ex: http://example.org/wp-content/themes/my-timber-theme).
path()string

Returns: The relative path to the theme (ex: /wp-content/themes/my-timber-theme).
theme_mod()string
theme_mods()array

Class Methods #

__construct() #

Constructs a new Timber\Theme object.

The Timber\Theme object of the current theme comes in the default Timber::context() call. You can access this in your twig template via {{ site.theme }}.

__construct( string $slug = null )

NameTypeDescription
$slugstring

PHP

<?php
$theme = new Timber\Theme("my-timber-theme");
$context['theme_stuff'] = $theme;
Timber::render('single.twig', $context);

Twig

We are currently using the {{ theme_stuff.name }} theme.

HTML

We are currently using the My Theme theme.

Returns: string Retrieves template directory URI for the active (child) theme. (ex: http://example.org/wp-content/themes/my-timber-theme).


path() #

Returns: string The relative path to the theme (ex: /wp-content/themes/my-timber-theme).


theme_mod() #

theme_mod( string $name, bool $default = false )

Returns: string

NameTypeDescription
$namestring
$defaultbool

theme_mods() #

Returns: array


get() #

Gets a raw, unformatted theme header.

see WP_Theme::get()

get( string $header )

Returns: false|string String on success, false on failure.

NameTypeDescription
$headerstringName of the theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.

Twig

{{ theme.get('Version') }}

display() #

Gets a theme header, formatted and translated for display.

see WP_Theme::display()

display( string $header )

Returns: false|string

NameTypeDescription
$headerstringName of the theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags.

Twig

{{ theme.display('Description') }}