Skip to content

Helpers & Common Functions

Most of the helper functions in our projects are located in functions/default/cleanHouse.php.
Some project-specific utilities can be found in functions/project/utilities/, for example: get-spacing.php.

These functions help with spacing classes, image handling, and other repetitive tasks.


$spacing = get_spacing($module['spacing']);

Returns a spacing class string for HTML elements based on a descriptive name.

  • Maps names like "top-large" or "bottom-small" to classes such as "u--pt-15 u--pt-tablets-10".
  • Supports top, bottom, or both.
  • Returns an empty string if no match is found.

Example use:

<?php
$spacing = get_spacing($module['spacing']);
$title = $module['title'];
$subtitle = $module['subtitle'];
?>
<section class="<?= $spacing ?>">
<h2><?= esc_html($title); ?></h2>
<p><?= esc_html($subtitle); ?></p>
</section>

Both functions generate <img> tags dynamically, supporting responsive sizes, lazy loading, aspect ratios, and optional <figure> with <figcaption>.

  • ACF Image Array or Attachment ID support.
  • Lazy loading with isLazy flag.
  • Srcset & sizes attributes for responsive images.
  • Alt attribute auto-detection via get_alt_image().
  • Optional figure wrapper and caption.
render_wp_image([
'image' => $image['image'],
'sizes' => '(max-width: 580px) 95vw, (max-width: 1024px) 50vw, 33vw',
'class' => 'example--class',
'isLazy' => $image['lazy'] ?? true,
'showAspectRatio' => true,
'decoding' => $image['decoding'] ?? 'async',
'fetchPriority' => $image['fetch_priority'] ?? 'auto',
'addFigcaption' => false,
]);

generate_image_tag() works similarly but is slightly lower-level and more customizable.


  • get_target_link($target, $text) – generates a link target attribute string with optional rel and aria-label.

Example use:

<a href="<?= esc_url($button['url']) ?>"
<?= get_target_link($button['target'], $button['title']) ?>>
<?= esc_html($button['title']) ?>
</a>
  • get_placeholder_image() – returns the default placeholder image URL from theme options.

  • Most helpers are designed to simplify common tasks in WordPress templates.
  • By centralizing these utilities, we avoid duplicating logic and ensure consistent output across the project.
  • They also help enforce best practices for accessibility (alt attributes), responsiveness (srcset), and performance (lazy loading).

Knowledge Check

Test your understanding of this section

Loading questions...