---
title: "Docs for developers · Focalio"
description: "Focalio's template functions, presets, WP-CLI commands and filters, with examples."
canonical_url: "https://focalio.eu/docs"
locale: en
meta:
  "og:description": "Focalio's template functions, presets, WP-CLI commands and filters, with examples."
  "og:image": "https://focalio.eu/images/og-en.png"
  "og:image:alt": "Focalio: Focal-point cropping, on demand."
  "og:image:height": "630"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Focalio · Docs for developers"
  "twitter:image": "https://focalio.eu/images/og-en.png"
---

> Index of every page on this site: [llms.txt](https://focalio.eu/llms.txt)

**For developers**

# Works with your theme. Even better with a line of PHP.

Images from `wp_get_attachment_image()`, srcset, your content and the block editor go through Focalio automatically. When you want full control, the helpers are there.

Focalio needs PHP 8.3 or newer, WordPress 6.2 or newer, and the Imagick or GD extension.

## **Without writing code**

Install Focalio and your theme's images are already served by it, cropped on the focal point you chose in the Media Library.

- `wp_get_attachment_image()`, `the_post_thumbnail()` and srcset: every size comes from Focalio, on demand.
- Images in posts and pages, when they show the attachment. An image block with an aspect ratio gets a real crop on the focal point.
- Cover and Media & Text blocks: their image position follows the focal point.
- The block editor: a Focalio panel for the Image block, a Cover with an image background and Media & Text with an image. On WordPress 7.1 the editor's own Crop buttons open Focalio's editor.

***Nothing to change**single.php*

```
<?php
the_post_thumbnail('large');
echo wp_get_attachment_image($id, 'medium_large');
```

## **In WordPress**

What Focalio adds to the WordPress admin, and below it what Focalio Pro adds to the same screens.

[![Focalio's Edit image window: a photo of an astronaut with the focal point on the helmet, and Rotate, Flip, Focal point and Crops in the sidebar.](https://focalio.eu/images/docs/editor.webp)](https://focalio.eu/images/docs/editor.webp)

***Edit image**Click or drag in the image to set the focal point; Centre puts it back in the middle. Rotate by quarter turns and flip, without touching the file. Reset all undoes everything.*

[![The Focalio box on an image's edit screen: a thumbnail with the focal point, its position, and the buttons Edit and Preview crops.](https://focalio.eu/images/docs/metabox.webp)](https://focalio.eu/images/docs/metabox.webp)

***The Focalio box**On the attachment screen, and the same in the Media Library's details: the focal point, Edit and Preview crops. On the attachment screen, Update saves it.*

[![The crop preview: the same photo as thumbnail, in its original ratio, as hero, card and portrait, the astronaut in frame in each.](https://focalio.eu/images/docs/crops.webp)](https://focalio.eu/images/docs/crops.webp)

***Preview crops**One tile per ratio of the WordPress sizes and presets (up to 12), each cut on the focal point, before you save.*

[![Focalio's Settings tab: image quality 82, output format, maximum width 2560, LQIP by default, crop fallback and image sizes on upload.](https://focalio.eu/images/docs/settings.webp)](https://focalio.eu/images/docs/settings.webp)

***Settings**Image quality (82 by default), output format (WebP or AVIF), maximum width, the blurred placeholder for every image (off by default), the crop fallback for images without a focal point (centre by default, or entropy or attention) and skipping image sizes on upload.*

[![Focalio's Presets tab: WordPress sizes to turn on or off, the presets hero 21:9, card 4:3 and portrait 4:5 with quality and LQIP, and the presets registered in code.](https://focalio.eu/images/docs/presets.webp)](https://focalio.eu/images/docs/presets.webp)

***Presets**Turn off the WordPress sizes the site doesn't use, and add presets with a ratio, a quality and LQIP of their own. Presets registered in code are listed below them, read-only.*

### **With Focalio Pro ****Pro**

The same screens with Pro active: a few extra controls where you set the focal point, and tabs and settings of its own.

[![The Edit image window with Pro: a frame with corner handles over the photo, a ruler from −45° to 45° under it, and in the sidebar Zoom, Detect faces and the history: a later version to go forward to, the current one, an earlier one and the original, each with a thumbnail.](https://focalio.eu/images/docs/pro-editor.webp)](https://focalio.eu/images/docs/pro-editor.webp)

***Edit image, with Pro**Zoom in on the focal point up to 3× with the slider or the frame's corner handles, straighten with the ruler under the image (up to 45°), and Detect faces. Every change goes into the image's history in the sidebar: each version with a thumbnail, who made it and what it was. Restore an earlier one and the later ones stay, to go forward to again, like undo and redo.*

[![The crop preview with Pro: the focal point in its title, and Adjust crop under the thumbnail, hero, card and portrait tiles.](https://focalio.eu/images/docs/pro-crops.webp)](https://focalio.eu/images/docs/pro-crops.webp)

***Preview crops, with Pro**The same tiles, with Adjust crop under every ratio of a WordPress size or preset: the thumbnail, hero, card and portrait here. The original ratio is never cut, so it has none.*

[![The Focalio box with Pro: Edit, Preview crops, Detect faces and the link History (2 earlier, 1 later).](https://focalio.eu/images/docs/pro-metabox.webp)](https://focalio.eu/images/docs/pro-metabox.webp)

***The Focalio box, with Pro**Detect faces puts the focal point on the faces. With the watermark on, No watermark on this image; once there is history, a link that opens the editor on it.*

[![The Crop for card window: a 4:3 frame drawn over the photo, the result next to it, its size in pixels and a zoom slider.](https://focalio.eu/images/docs/adjust-crop.webp)](https://focalio.eu/images/docs/adjust-crop.webp)

***A crop of your own**Each tile of the crop preview gets Adjust crop: draw the frame for that one ratio, and the focal point still decides every other one.*

[![The Settings tab with Pro: AVIF with WebP fallback among the output formats, and the rows Faces and Watermark.](https://focalio.eu/images/docs/pro-settings.webp)](https://focalio.eu/images/docs/pro-settings.webp)

***Settings, with Pro**AVIF with WebP as fallback, faces on upload (the focal point on the faces in every new image) and the watermark, with its image, position, size, opacity and margin.*

[![The Cache tab with Pro: the image cache, Cache warm-up with Every page and Every image, and Warm automatically for changed images.](https://focalio.eu/images/docs/pro-cache.webp)](https://focalio.eu/images/docs/pro-cache.webp)

***Cache warm-up**Render every page's images and every preset ahead of the first visitor, and render a changed image again by itself after an upload or an edit.*

[![The Import / export tab: Download settings, and an import from a file or pasted text with Check first.](https://focalio.eu/images/docs/pro-transfer.webp)](https://focalio.eu/images/docs/pro-transfer.webp)

***Import / export**Download the settings as a file and import them on another site; Check first shows what would change. The sign key and the cache never go along.*

[![Focalio across the network: every site with its cache and warm-up, Warm up every site, and a template site for new sites.](https://focalio.eu/images/docs/pro-network.webp)](https://focalio.eu/images/docs/pro-network.webp)

***Across the network**On a multisite, every site on one screen with its cache and warm-up, and a template site whose settings new sites start with, or that you copy to every site at once.*

The photo: Bruce McCandless II on the first untethered spacewalk, 1984. NASA, public domain.

## **In templates**

`glide_image()` renders a responsive `<img>` for any ratio: srcset, lazy loading, and a blurred placeholder if you want one.

Named arguments use the parameter names as they are in PHP: `maxWidth:`, not `max_width:`. The helpers start with `glide_` and some filters with `wp_glide/`: names from before Focalio had its name, kept so existing code keeps working.

***In a template**single.php*

```
<?php
echo glide_image(
    get_post_thumbnail_id(),
    '16:9',
    lazy: false,
    priority: true,
);
```

### **Parameters **`glide_image()`

<dl>

<dt>**$image**int|array|string|null</dt>
<dd>Attachment ID or ACF image array (with its focal point, alt text and placeholder), a path relative to the uploads folder or an uploads URL (as it is). <code>null</code> gives an empty string.</dd>

<dt>**$aspect**string</dt>
<dd>The ratio as W:H, like 16:9, or the name of a preset.</dd>

<dt>**$class**?string = null</dt>
<dd>The class attribute of the <code>&lt;img&gt;</code>.</dd>

<dt>**$maxWidth**?int = null</dt>
<dd>The largest width in the srcset: lower than the Maximum width setting if you like, never above it or the original's.</dd>

<dt>**$sizes**?string = null</dt>
<dd>The sizes attribute. By default <code>100vw</code>.</dd>

<dt>**$lazy**bool = true</dt>
<dd><code>loading="lazy"</code> and <code>decoding="async"</code>. Turn it off for the largest image at the top of the page.</dd>

<dt>**$priority**bool = false</dt>
<dd><code>fetchpriority="high"</code>, for that same image.</dd>

<dt>**$quality**?int = null</dt>
<dd>Image quality, up to 100. By default the preset's quality, else the site's.</dd>

<dt>**$lqip**?bool = null</dt>
<dd>The blurred placeholder while loading. <code>null</code> follows the preset, else the site. For attachment IDs and ACF image arrays.</dd>

</dl>

An aspect that is neither W:H nor a preset throws an `InvalidArgumentException`; so does a 0 in the ratio, and preset names are case-sensitive. A missing image gives an empty string, whatever the aspect.

`glide_source()` gives the `<source>` for a `<picture>`, to show another ratio on small screens.

***Art direction**single.php*

```
<picture>
    <?= glide_source($id, '1:1', media: '(max-width: 767px)') ?>
    <?= glide_image($id, '16:9', 'w-full') ?>
</picture>
```

`glide_url()` returns just the address of a rendition, or `null` for a missing image. With `fit=crop` it crops an attachment ID on the focal point. `glide_placeholder()` returns the blurred placeholder as a data URI, or `null`.

***Just the URL**single.php*

```
<?php
$url = glide_url($id, ['w' => 600, 'h' => 600, 'fit' => 'crop']);
$blur = glide_placeholder($id, '1:1');
```

## **Presets**

Name a ratio once, with its own quality and placeholder, and templates stay short. Register it in your theme's functions.php or a plugin, or add it under Focalio, Presets in the admin.

A preset has an aspect ratio, a quality (40 to 100; leave it out for the site's setting) and a placeholder setting (`true`, `false`, or `null` to follow the site). Names are lowercase letters, digits, - and \_, up to 32 characters, starting and ending with a letter or digit; capitals and spaces become lowercase and hyphens.

***Register a preset**functions.php*

```
<?php
glide_register_preset('hero', '21:9', quality: 80, lqip: true);
```

Use it by name in `glide_image()` and `glide_source()`, or as a WordPress image size: in `wp_get_attachment_image()`, in the block editor's resolution menu and in ACF. No files are written for it.

***Use it by name**single.php*

```
<?php
echo glide_image($id, 'hero');
echo wp_get_attachment_image($id, 'hero');
```

The same with a filter, if you prefer it. Presets from code win over the ones made in the admin.

***Or with a filter**functions.php*

```
add_filter('wp_glide/register_presets', function (array $presets): array {
    $presets['hero'] = ['aspect' => '21:9', 'quality' => 80];
    return $presets;
});
```

## **WP-CLI**

Look into the image cache, clean it up or empty it, and work out focal points in bulk.

<dl>

<dt>**wp focalio cache stats**</dt>
<dd>How many rendered images are in the cache, and how many the cleanup would remove.</dd>

<dt>**wp focalio cache cleanup [--dry-run]**</dt>
<dd>Run the weekly cleanup now; with <code>--dry-run</code> it only counts. It stops after 20 seconds: run it again for the rest.</dd>

<dt>**wp focalio cache clear [--yes]**</dt>
<dd>Delete every rendered image. Asks first, unless you add <code>--yes</code>. Your originals are never touched.</dd>

<dt>**wp focalio guess [--force]**</dt>
<dd>Work out the automatic focal point (entropy or attention, as set) of every image ahead of time; <code>--force</code> redoes the ones already known. Not when the automatic point is set to the centre.</dd>

</dl>

***From the command line**terminal*

```
$ wp focalio cache stats
$ wp focalio cache cleanup --dry-run
$ wp focalio cache clear --yes
$ wp focalio guess --force
```

## **Configuration**

The settings have filters, for when a value belongs in code. A few useful ones:

***Adjust a default**functions.php*

```
add_filter('wp_glide/max_width', fn () => 1920);
add_filter('focalio/cache_max_age_days', fn () => 90);
```

| Filter | Default | What it does |
| --- | --- | --- |
| **wp\_glide/max\_width** | 2560 | The largest width in a srcset: the Settings tab's value |
| **wp\_glide/quality** | 82 | Image quality: the Settings tab's value, 82 out of the box |
| **wp\_glide/format** | 'webp' | webp or avif: the Settings tab's value |
| **wp\_glide/default\_format** |  | The format added to an address that asks for none ($path); '' keeps the source's. Animated GIFs always keep theirs |
| **wp\_glide/lqip** | false | Blurred placeholders across the site: the Settings tab's value |
| **wp\_glide/route\_prefix** | 'img' | The first part of image addresses (/img/…) |
| **wp\_glide/cache\_path** | uploads/.glide-cache | Where rendered images are kept |
| **wp\_glide/driver** | 'imagick' \| 'gd' | imagick, else gd |
| **focalio/image\_params** |  | The last word on an image's parameters (array $params, int $id, ?array $transform, string $context) |
| **focalio/cache\_max\_age\_days** | 180 | Days before the weekly cleanup removes a rendered image; 0 keeps them |
| **focalio/virtual\_sizes\_keep** | \['thumbnail'] | Sizes still saved on upload when Image sizes on upload is on |
| **focalio/early\_serve** | true | Serve cached images before WordPress loads; `false` from a must-use plugin, like `FOCALIO_EARLY_SERVE` |
| **focalio/replace\_image\_editor** | true | On WordPress 7.1, the block editor's Crop buttons open Focalio's editor; `false` gives back WordPress's own |

Image addresses are signed, so nobody can ask your server for any size they like: a wrong signature gets a 403. Focalio makes the key itself. Define `GLIDE_SIGN_KEY` to keep it the same across environments; Focalio, Security shows the line to paste.

Focalio serves images it has already made before WordPress loads, which is what makes them fast. `FOCALIO_EARLY_SERVE` set to `false` turns that off: in wp-config.php or a must-use plugin, because it's read while plugins load. The `focalio/early_serve` filter does the same.

***In wp-config.php**wp-config.php*

```
define('GLIDE_SIGN_KEY', 'your-own-long-random-key');
define('FOCALIO_EARLY_SERVE', false);
```

## **What Pro adds ****Pro**

Focalio Pro is an add-on to the plugin above. Your templates stay as they are: Pro adds to what they render. It comes with a licence, not as a download from this site.

- Zoom, straighten and a crop of your own per ratio, set per image in the Media Library. `glide_image()`, `glide_url()` and `wp_get_attachment_image()` follow them by themselves. In `glide_url()`, a crop you pass yourself (crop-x-y-zoom) is left alone, and passing st or mark leaves out the straightening or the watermark.
- Version history per image: every change to the focal point, orientation, zoom, angle, crops and watermark choice, the last 20, with a thumbnail each. Go back and forward, like undo and redo.
- AVIF with WebP as a fallback: images in your content and from `wp_get_attachment_image()` get a `<picture>` with AVIF. `glide_image()` and `glide_source()` keep giving WebP.
- A watermark from the Media Library: one of nine positions, a size, an opacity and a margin, left off small images. Leave it off per image or per preset.
- Changed images are rendered again by themselves: after an upload, or when the focal point, orientation, zoom, angle, a crop or the watermark changes. New uploads get their focal point on the faces.
- Four WP-CLI commands: render the cache ahead of the first visitor, put the focal point on faces, and export or import the settings.
- Import and export the settings, on a tab of their own or with WP-CLI, to copy them to another site. The sign key and the cache never go along.
- WooCommerce: a block theme's shop grid cropped on the focal point by itself, and a ratio for every photo on a product page.
- Multisite: a Focalio screen in the Network Admin with every site's cache and warm-up, a template site whose settings new sites can start with (or that you copy to every site at once), and one licence for the network. warm and faces take `--network`.
- Filters for themes: `focalio_pro/preset_watermark` leaves a preset out of the watermark, `focalio_pro/woocommerce_crop` leaves an image in a block theme's shop grid as WooCommerce made it.

***Pro on the command line**terminal*

```
$ wp focalio warm --images
$ wp focalio faces --dry-run
$ wp focalio warm --network
$ wp focalio settings export --file=focalio.json
```

<dl>

<dt>**wp focalio warm [--pages] [--images] [--network]**</dt>
<dd>Render every image ahead of time: the ones on your pages (<code>--pages</code>), every preset and size (<code>--images</code>), or both.</dd>

<dt>**wp focalio faces [--force] [--dry-run] [--network]**</dt>
<dd>Put the focal point on the faces in every image. Images with a focal point, or already looked at, are skipped unless <code>--force</code>; <code>--dry-run</code> only reports.</dd>

<dt>**wp focalio settings export [--file=&lt;file&gt;]**</dt>
<dd>Write the settings as JSON to a file, or to the screen without <code>--file</code>.</dd>

<dt>**wp focalio settings import &lt;file&gt; [--dry-run]**</dt>
<dd>Read them from a file (or - for the input); <code>--dry-run</code> shows what would change.</dd>

</dl>

***Pro filters**functions.php*

```
add_filter('focalio_pro/preset_watermark', function (?bool $choice, string $preset) {
    return $preset === 'avatar' ? false : $choice;
}, 10, 2);

add_filter('focalio_pro/woocommerce_crop', function (bool $crop, int $id) {
    return $id === 123 ? false : $crop;
}, 10, 2);
```

The full Pro docs come with the plugin.

- [Compare Free and Pro](https://focalio.eu/#compare)
- [See the prices](https://focalio.eu/#pricing)

## **Questions?**

Ask in the support forum on WordPress.org, or send us a message.

- [Support forum(opens in a new tab)](https://wordpress.org/support/plugin/focalio/)
- [Contact](https://focalio.eu/contact)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://focalio.eu/#website","@type":"WebSite","description":"Choose what stays in frame for each image. Focalio crops every image on demand, as WebP with a blurred placeholder, without filling your uploads folder with image sizes.","inLanguage":"en-US","name":"Focalio","url":"https://focalio.eu/","publisher":{"@id":"https://focalio.eu/#identity"},"workTranslation":{"@id":"https://focalio.nl/#website"}},{"@id":"https://focalio.eu/docs#webpage","@type":"WebPage","description":"Focalio's template functions, presets, WP-CLI commands and filters, with examples.","name":"Docs for developers","url":"https://focalio.eu/docs","isPartOf":{"@id":"https://focalio.eu/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://focalio.eu/docs"]}]},{"@id":"https://focalio.eu/#identity","@type":"Organization","name":"BIG FAT","url":"https://www.bigfat.nl/"},{"@id":"https://focalio.eu/docs#article","description":"Focalio's template functions, presets, WP-CLI commands and filters, with examples.","headline":"Works with your theme. Even better with a line of PHP.","inLanguage":"en-US","thumbnailUrl":"https://focalio.eu/images/og-en.png","@type":["Article","TechArticle"],"author":{"@id":"https://focalio.eu/#identity"},"image":{"@id":"https://focalio.eu/#/schema/image/1"},"isPartOf":{"@id":"https://focalio.eu/docs#webpage"},"mainEntityOfPage":{"@id":"https://focalio.eu/docs#webpage"},"publisher":{"@id":"https://focalio.eu/#identity"}},{"@id":"https://focalio.eu/#/schema/image/1","@type":"ImageObject","contentUrl":"https://focalio.eu/images/og-en.png","inLanguage":"en-US","url":"https://focalio.eu/images/og-en.png"}]}
```

## Sitemap

See the full [sitemap](https://focalio.eu/sitemap.md) for all pages.
