Custom Functionalities
This section documents the custom utility functions available across the theme. These functions help standardize tasks like spacing, rendering image tags, and setting target link attributes.
πΌοΈ generate_image_tag()
Section titled βπΌοΈ generate_image_tag()βThis function dynamically generates an <img>
HTML tag (or <figure>
with <figcaption>
) from either an ACF image field or a featured image ID. It supports lazy loading, responsive images, SVGs, and custom data-*
attributes.
π Key Features
Section titled βπ Key Featuresβ- Works with ACF image arrays and attachment IDs.
- Supports custom CSS classes, lazy loading, and decoding strategies.
- Can output
<figure>
wrappers with captions. - Responsive with
srcset
,sizes
, and placeholder support. - Accepts
dataAttributes
as an associative array.
π§Ύ Usage Example
Section titled βπ§Ύ Usage Exampleβ<?php if ($quote_logo): ?> <?php $image_tag_args = array( 'image' => $quote_logo, 'sizes' => '135px', 'class' => 'g--card-05__ft-items__media-wrapper__media', 'isLazy' => true, 'showAspectRatio' => true, 'decodingAsync' => true, 'fetchPriority' => false, 'addFigcaption' => false, ); ?> <figure class="g--card-05__ft-items__media-wrapper"> <?php generate_image_tag($image_tag_args); ?> </figure><?php endif; ?>
π get_spacing()
Section titled βπ get_spacing()βThis function maps semantic spacing names (like top-large
, bottom-small
) to utility class combinations that apply padding on desktop and tablet viewports. This is a custom ACF field created by Terra.
π§Ύ Example Input/Output
Section titled βπ§Ύ Example Input/Outputβ$spacing = get_spacing($module['section_spacing']);
If the $module['section_spacing']
value is 'top-large-bottom-small'
, the function returns:
f--pt-15 f--pt-tablets-10 f--pb-5 f--pb-tablets-4
This helps enforce consistent spacing design tokens across the theme.
π get_target_link()
Section titled βπ get_target_link()βReturns a fully-formed target
attribute string for anchor tags, including:
target="_blank"
or_self
rel="noopener noreferrer"
(for external links)aria-label
for accessibility
π§Ύ Example Usage
Section titled βπ§Ύ Example Usageβ<a href="https://example.com" <?php echo get_target_link(true, 'Example Link'); ?>> Example Link</a>
π Output
Section titled βπ Outputβtarget='_blank' rel='noopener noreferrer' aria-label='Example Link, opens a new window'
These helper functions are part of our shared library and are meant to improve consistency, accessibility, and maintainability in all theme development work.
π get_page_id_by_title()
Section titled βπ get_page_id_by_title()βThis function returns the WordPress page ID for a given page title.
π§Ύ Example Usage
Section titled βπ§Ύ Example Usageβ$page_id = get_page_id_by_title('Contact');
This is useful when you need to programmatically reference a page without hardcoding its ID.
π Output
Section titled βπ OutputβReturns an int
representing the post ID of the matching page. If no page is found, it will return null
.