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.
get_spacing()
Section titled βget_spacing()β$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>render_wp_image() & generate_image_tag()
Section titled βrender_wp_image() & generate_image_tag()βBoth functions generate <img> tags dynamically, supporting responsive sizes, lazy loading, aspect ratios, and optional <figure> with <figcaption>.
Key Features
Section titled βKey Featuresβ- ACF Image Array or Attachment ID support.
- Lazy loading with
isLazyflag. - 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.
Other Useful Helpers
Section titled βOther Useful Helpersβget_target_link($target, $text)β generates a linktargetattribute string with optionalrelandaria-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 (
altattributes), responsiveness (srcset), and performance (lazy loading).
Knowledge Check
Test your understanding of this section
Loading questions...