Helper functions

The wonder_* functions wonderpress-core puts at a theme’s disposal. Every one is wrapped in function_exists, so a theme can replace any of them by defining its own version first.

The functions below are the ones you call from templates, views, and functions.php. Core also contains internal machinery under the same prefix (manifest loaders, ACF group builders, the wonder_normalize_* value normalizers); those run on hooks and are not meant to be called from theme code, though the normalizers’ behavior is documented in Field types.

Composition and hydration

wonder_partial_props( $slug, $instance_id = null )

Constructor args for a PHP-rendered, ACF-compatible partial. Returns array( 'acf' => get_field( … ) ) so the partial’s ingestion hydrates matching properties, and an empty array when ACF is absent or the field has no value, which is what lets core no-op without the plugin.

With one argument, it reads the field named by the partial slug (the wonderpress_template_fields location style). With two, it reads the template composition instance id instead:

code
( new \Wonderpress\Partials\Hero( wonder_partial_props( 'hero' ) ) )->render();( new \Wonderpress\Partials\Landing_Hero( wonder_partial_props( 'landing-hero', 'hero-main' ) ) )->render();
ParamTypeDescription
$slugstringThe partial slug. Used as the ACF field name when no instance id is given.
$instance_idstring or nullTemplate composition instance id (the ACF group field name).

wonder_template_composition_field( $instance_id )

Values for an inline fields composition row (one with properties and no partial). Returns the group value as an array, or an empty array when ACF is absent or the id is empty.

code
 seo = wonder_template_composition_field( 'seo' );echo esc_html( $seo['meta_description'] ?? '' );

wonder_render_partial_ref( $partial_slug, $acf_data )

Hydrate and render a partial from an embedded ACF group value: the rendering half of a type: "partial" property. Normalizes the value against the referenced manifest, constructs the class with array( 'acf' => $acf_data ), and returns the HTML (empty string when the class is missing or the data is not an array). Note the return: unlike a direct ->render(), you echo this yourself.

code
echo wonder_render_partial_ref( 'link', $this->cta ); // phpcs:ignore -- partial escapes internally

wonder_render_template_sections( $template_slug = null )

Render every partial row in a template manifest’s composition, in order, each hydrated through wonder_partial_props( partial, id ). With no argument it resolves the current page’s template. For a page that is only named partials in sequence; do not mix it with handwritten renders in the same template, and note that fields rows are skipped (they have no render of their own). A row referencing an unknown partial triggers _doing_it_wrong rather than a fatal.

Rendering primitives

wonder_image( $params, $echo = true )

Render an <img> (or <picture>) through the core Image partial.

code
wonder_image( array( 'src' => $url, 'alt' => $alt, 'size' => 'medium' ) );wonder_image( array( 'acf' => get_field( 'photo' ) ) );
Param keyTypeDescription
srcstringThe image src. Required (unless hydrating via acf).
acfarrayAn ACF image array; hydrates src and friends, picking size from the ACF sizes map.
altstringAlternative text.
sizestringWP image size (default large).
classesstring or arrayElement classes (default theme-image).
attributesarrayArbitrary extra attributes.
width, heightstringAttribute values only.
sizesstringThe HTML sizes attribute (distinct from an ACF array’s sizes map).
srcsetstring or arrayA native srcset string, or an art-direction map of min-width to URL for <picture>.
decodingstringasync (default), sync, or auto.

Pass false as the second argument to return the HTML instead of echoing.

wonder_link( $params, $echo = true )

Render an <a> through the core Link partial.

code
wonder_link( array( 'content' => 'Read more', 'url' => $url, 'open_in_new_tab' => true ) );
Param keyTypeDescription
contentstringText inside the anchor. Required.
urlstringThe href. Required (the rich ACF payload can derive it, see wonder_link_url_from_acf).
open_in_new_tabbooleanAdds target="_blank" with safe rel tokens (default false).
titlestringTitle attribute for screen readers.
typestringThe rich Link primitive’s target type.
classesstring or arrayElement classes.
attributesarrayArbitrary extra attributes.

wonder_nav( $location = 'header-menu' )

wp_nav_menu() with Wonderpress defaults: no container markup, a bare <ul> wrapper, wp_page_menu fallback. For full control over the markup, use wonder_get_menu_array() and write the HTML yourself.

wonder_get_menu_array( $location )

A WordPress menu as a plain associative array. Accepts a registered theme location, or a menu id, slug, or name. Each top-level item carries a children array; nesting resolves one level deep (children of children are ignored). Returns an empty array when no menu is assigned.

code
foreach ( wonder_get_menu_array( 'header-menu' ) as $item ) {	// $item['title'], $item['url'], $item['children']}

wonder_include_template_file( $_filename, $_params = array(), $_return = false )

Render a theme file with an explicit set of local variables, located through locate_template() so a child theme can override it. Each $_params key becomes a local variable in the included file, which is the same mechanism partial views use. Pass true as the third argument to return the output instead of echoing. Returns an empty string (or null when echoing) if the file does not exist.

wonder_rte_filter( $content )

Wrap WYSIWYG content in <div class="theme-rte"> and stamp a theme-rte__<tag> class onto each child element (p, h1 through h6, ul, li, a, img, figure, figcaption, blockquote, strong, table, hr). Applies the_content filters first, with a recursion guard so it can itself be hooked into the_content. This is what lets rich-text styles scope cleanly in SCSS without a cascade of descendant selectors.

code
echo wonder_rte_filter( get_field( 'body' ) ); // phpcs:ignore -- content passes through the_content

Page identity and assets

wonder_body_id( $body_id = null )

Getter and setter in one. A template calls it with a string early (before header.php renders) to declare the page’s id; called with no argument it returns what was set, or 'body'. The value does double duty: it is the <body> id, and it selects which Static Kit bundle loads, since core enqueues static/dist/{css,js}/<wonder_body_id()>.{css,js}.

code
wonder_body_id( 'landing' );get_header();

wonder_asset_path( $type )

The current template’s bundle path relative to the theme, for 'css' or 'js'. Tries static/dist/<type>/<wonder_body_id()>.<type>, then falls back to the shared global bundle; returns null when neither exists. The candidate list is filterable through wonderpress_asset_candidates, which is the opt-out for a different build layout (hashed filenames, another output directory). You rarely call this directly; core’s enqueue pass uses it.

wonder_prefer_inline_css( $preferred = null ) / wonder_prefer_inline_js( $preferred = null )

Getter and setter toggles, same pattern as wonder_body_id. Set true in functions.php and core prints the bundle inline in the document instead of enqueuing a file, which trades cacheability for a round trip. Default false.

Small pure helpers the Link primitive uses, available to theme code too.

wonder_link_append_query_params( $url, $query_params )

Append a query string fragment to a URL. Accepts a leading ? or bare key=value pairs, preserves an existing fragment, and merges through add_query_arg() when WordPress is loaded.

wonder_link_merge_rel( $open_in_new_tab, $existing_rel = '' )

Merge rel tokens so a new-tab link keeps noopener noreferrer even when the caller also passes its own rel (such as nofollow). Returns the deduplicated token string.

wonder_link_url_from_acf( array $acf )

Build an href from a rich Link primitive payload when url is empty: resolves the type switch (internal, file, email, telephone) to a concrete URL.

Debugging

wonder_dd( $payload = null )

Dump and die: var_dump in a <pre>, then die(). Development only, obviously.

wonder_handle_exception( \Exception $e )

Dump the exception when WP_DEBUG is true; swallow it silently otherwise. Partials route their render-time failures through this, so a missing required property is loud locally and quiet in production.