Helper Functions
The helpers.php file contains several functions to help optimize and speed up the development workflow. Each function is documented below.
Echo Static Text
Usage: Used to echo static text in the theme.
Parameters:
$string: The string to be echoed.
Wrap ACF Content
Usage: Wraps an Advanced Custom Fields (ACF) field in a specified HTML element.
Parameters:
$field: The ACF field to be wrapped.$element: (Optional) The HTML element used for wrapping. Default isdiv.$class: (Optional) The class name for the wrapping element. Default isnc.
Buttons
Usage: Generates a button using ACF link field (or link array).
Parameters:
$link: ACF link array.$class: (Optional) Class for the anchor tag. Default isnc.$attr: (Optional) Additional attributes for the anchor tag.
SVGs
Usage: Gets the content of an SVG from a defined path based on its name.
Parameters:
$name: SVG filename without the extension (File must be uploaded toassets/svg).$return: (Optional) Iftrue, the function returns the SVG content. Iffalse, it echoes it. Default isfalse.
SVG Sprite
Usage: Generates SVG sprite markup.
Parameters:
$name: Sprite name.$id: (Optional) ID for the SVG element.$return: (Optional) Iftrue, returns the SVG markup. Iffalse, it echoes it. Default isfalse.
Image
Usage: Echos an image from a WordPress attachment.
Parameters:
$image: Image array from WordPress.$size: (Optional) Image size. Default isfull.
Flexible Content Fields
Usage: Loops through ACF flexible content fields and includes a template part based on the current layout.
Replace Brackets in String with HTML
Usage: Replaces square brackets in a string with specified HTML tags.
Parameters:
$string: The string with square brackets to be replaced.$el: (Optional) The HTML element to replace the brackets. Default isspan.$class: (Optional) The class name for the element. Default isnc.
Get Share Links
Usage: Displays a list of social share links.
Parameters:
$url: (Optional) The URL to be shared. If not provided, it uses the current post's permalink.
Parse URL Parameters into Array
Usage: Converts a URL query string into an associative array.
Parameters:
$str: The URL query string to be parsed.