Skip to content

Kirby 3.9.8

$page->image()

Returns a specific image by filename or the first one

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

Parameters

Name Type Default
$filename string|null null

Return type

Kirby\Cms\File|null

Parent class

Kirby\Cms\Page

Example

Fetching the first image

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

Fetching a specific image

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

What is an image file?

Kirby considers the following file types as images:

  • jpeg
  • jpg
  • jpe
  • gif
  • png
  • svg
  • ico
  • tif
  • tiff
  • bmp
  • psd
  • ai
  • eps
  • ps
  • webp (since v3.2.0)