Timber Logo

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

Timber\​Site

Timber\Site gives you access to information you need about your site. In Multisite setups, you can get info on other sites in your network.

PHP

$other_site_id = 2;

$context = Timber::context( [
'other_site' => new Timber\Site( $other_site_id ),
] );

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

Twig

My site is called {{site.name}}, another site on my network is {{other_site.name}}

HTML

My site is called Jared's blog, another site on my network is Upstatement.com

Overview #

This class extends Timber\Core
This class implements Timber\CoreInterface

Properties #

NameTypeDescription
$admin_emailstringThe admin email address set in the WP admin panel
$blognamestring
$charsetstring
$descriptionstring
$idintthe ID of a site in multisite
$languagestringthe language setting ex: en-US
$multisitebooltrue if multisite, false if plain ole' WordPress
$namestring
$pingback_urlstringfor people who like trackback spam
$siteurlstring
$theme\Timber\Theme
$titlestring
$urlstring
$home_urlstring
$site_urlstring
$rdfstring

Methods #

NameReturn TypeSummary/Returns
__call()mixedMagic method dispatcher for site option fields, for convenience in Twig views.

Returns: The value of the option field named $field if truthy, false otherwise.
__construct()Constructs a Timber\Site object
__get()mixedGet the value for a site option.

Returns: The option value.
icon()null or \Timber\Image
link()stringReturns the link to the site's home.
meta()Get the value for a site option.
option()mixedGet the value for a site option.

Returns: The option value.

Class Methods #

__construct() #

Constructs a Timber\Site object

__construct( string|int $site_name_or_id = null )

NameTypeDescription
$site_name_or_idstring or int

PHP

//multisite setup
$site = new Timber\Site(1);
$site_two = new Timber\Site("My Cool Site");
//non-multisite
$site = new Timber\Site();

__call() #

Magic method dispatcher for site option fields, for convenience in Twig views.

Called when explicitly invoking non-existent methods on the Site object. This method is not meant to be called directly.

link https://secure.php.net/manual/en/language.oop5.overloading.php#object.call

__call( string $option, array $arguments )

Returns: mixed The value of the option field named $field if truthy, false otherwise.

NameTypeDescription
$optionstringThe name of the method being called.
$argumentsarrayEnumerated array containing the parameters passed to the function. Not used.

The following example will dynamically dispatch the magic __call() method with an argument of "users_can_register" #}

Twig

{% if site.users_can_register %}
{# Show a notification and link to the register form #}
{% endif %}

---

### \_\_get()

Get the value for a site option.

`__get( string $option )`

**Returns:** `mixed` The option value.

| Name | Type | Description |
| --- | --- | --- |
| $option | `string` | The name of the option to get the value for. |

**Twig**

```twig
Published on: {{ post.date|date(site.date_format) }}

option() #

Get the value for a site option.

option( string $option )

Returns: mixed The option value.

NameTypeDescription
$optionstringThe name of the option to get the value for.

Twig

Published on: {{ post.date|date(site.option('date_format')) }}

meta() #

Get the value for a site option.

DEPRECATED since 2.0.0, use {{ site.option }} instead

meta( mixed $option )


icon() #

Returns: null|\Timber\Image


Returns the link to the site's home.

Returns: string

Twig

<a href="{{ site.link }}" title="Home">
<img src="/wp-content/uploads/logo.png" alt="Logo for some stupid thing" />
</a>

HTML

<a href="http://example.org" title="Home">
<img src="/wp-content/uploads/logo.png" alt="Logo for some stupid thing" />
</a>