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 #
Name | Type | Description |
---|---|---|
$name | string | the human-friendly name of the theme (ex: My Timber Starter Theme ) |
$version | string | the version of the theme (ex: 1.2.3 ) |
$parent | \Timber\Theme | the Timber\Theme object for the parent theme |
$parent_slug | string | the slug of the parent theme (ex: _s ) |
$slug | string | the slug of the theme (ex: my-timber-theme ) |
$uri | string | Retrieves template directory URI for the active (parent) theme. (ex: http://example.org/wp-content/themes/my-timber-theme ). |
Methods #
Name | Return Type | Summary/Returns |
---|---|---|
__construct() | Constructs a new Timber\Theme object. | |
display() | false or string | Gets a theme header, formatted and translated for display. |
get() | false or string | Gets 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 )
Name | Type | Description |
---|---|---|
$slug | string |
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.
link() #
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
Name | Type | Description |
---|---|---|
$name | string | |
$default | bool |
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.
Name | Type | Description |
---|---|---|
$header | string | Name 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
Name | Type | Description |
---|---|---|
$header | string | Name of the theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags. |
Twig
{{ theme.display('Description') }}