Skip to content

🧰 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

lp__e($string);

Usage: Used to echo static text in the theme.

Parameters:

  • $string: The string to be echoed.

Wrap ACF Content

lp_field($field, $element='div', $class='nc');

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 is div.
  • $class: (Optional) The class name for the wrapping element. Default is nc.

Buttons

lp_btn($link, $class='nc', $attr=false);

Usage: Generates a button using ACF link field (or link array).

Parameters:

  • $link: ACF link array.
  • $class: (Optional) Class for the anchor tag. Default is nc.
  • $attr: (Optional) Additional attributes for the anchor tag.

SVGs

lp_svg($name, $return = false);

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 to assets/svg).
  • $return: (Optional) If true, the function returns the SVG content. If false, it echoes it. Default is false.

SVG Sprite

lp_sprite($name, $id = false, $return = false);

Usage: Generates SVG sprite markup.

Parameters:

  • $name: Sprite name.
  • $id: (Optional) ID for the SVG element.
  • $return: (Optional) If true, returns the SVG markup. If false, it echoes it. Default is false.

Image

lp_img($image, $size='full');

Usage: Echos an image from a WordPress attachment.

Parameters:

  • $image: Image array from WordPress.
  • $size: (Optional) Image size. Default is full.

Flexible Content Fields

lp_flexible_content();

Usage: Loops through ACF flexible content fields and includes a template part based on the current layout.

Replace Brackets in String with HTML

lp_unbracket($string, $el = 'span', $class = 'nc');

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 is span.
  • $class: (Optional) The class name for the element. Default is nc.
lp_share_links($url = null);

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

lp_parse_str($str);

Usage: Converts a URL query string into an associative array.

Parameters:

  • $str: The URL query string to be parsed.