Skip to content

Custom Data

The sleekPixel/data/custom filter adds entries to the Custom group of the editor’s dynamic data. Each entry is an array with three keys:

  • value: the entry’s ID. In a text or an image source it is used as {custom.<value>}.
  • label: the name the editor lists it under.
  • data: the text the image shows. Return a string.

The first entry below reads the ACF field subtitle of the post the image is rendered for; the second is a fixed text.

PHP
add_filter('sleekPixel/data/custom', function ($entries, $args) {
  $postId = (int) ($args['postId'] ?? 0);
  $subtitle = $postId ? get_field('subtitle', $postId) : '';

  $entries[] = [
    'value' => 'subtitle',
    'label' => 'Subtitle',
    'data' => is_string($subtitle) ? $subtitle : '',
  ];

  $entries[] = [
    'value' => 'campaign',
    'label' => 'Campaign line',
    'data' => 'Summer sale: 20% off',
  ];

  return $entries;
}, 10, 2);

When the filter runs

  • When the editor loads, to build its list, with postId set to 0. Only value and label matter here.
  • When an image renders, with the post’s ID in postId. One of these calls also passes the design’s settings, elements, other and locations, so data can depend on both the post and the image.

When an image renders, an entry without a value, a label or a data, or whose data is null, is left out, and its placeholder renders as empty text. Return an empty string rather than null when a post has no value; a function such as get_field() returns null for a missing field.

The filter’s parameters are in the hooks reference.

Stay in the Loop!  

Be the first to hear about new updates, special offers, and helpful tips, delivered straight to your inbox.

We respect your inbox (and your privacy). Read our privacy policy.