Skip to content

Kirby 5.0.4

$site->image()

Returns a specific image by filename or the first one

$site->image(string|null $filename = null): Kirby\Cms\File|null

Parameters

Name Type Default
$filename stringornull null

Return types

Kirby\Cms\Fileornull

This method modifies the existing $site object it is applied to and returns it again.

Parent class

Kirby\Cms\Site

Examples

Fetching the first image

<?php if ($image = $site->image()): ?>
<img src="<?= $image->url() ?>" alt="">
<?php endif ?>

Fetching a specific image

<?php if ($image = $site->image('myimage.jpg')): ?>
<img src="<?= $image->url() ?>" alt="">
<?php endif ?>