> For the complete documentation index, see [llms.txt](https://whoisandywhite.gitbook.io/porterwp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whoisandywhite.gitbook.io/porterwp/developer-api/theme-helpers.md). Agents can also search and read this documentation through its [MCP server](https://whoisandywhite.gitbook.io/porterwp/~gitbook/mcp).

# Theme helpers

PorterWP loads a set of global helpers for common block-theme tasks. Theme code may call these after the plugin has initialized.

## Content and template helpers

### `wpautoheading( $content, $level = 'h2', $classes = [] )`

Wraps safe post HTML in one of `h1`–`h6`, `p`, `div` or `span`. Invalid element names fall back to `h2`; every class token is sanitized.

```php
echo wpautoheading(
    get_field( 'heading' ),
    'h2',
    [ 'section-title', 'has-large-font-size' ]
);
```

### `porter_custom_template_part_exists( $slug )`

Returns `true` when a published `wp_template_part` or `parts/{slug}.html` exists. The slug is sanitized before lookup.

### `porter_safe_return_template_part( $slug )`

Renders an existing template part and returns its HTML, or an empty string if it cannot be found. Registered style, script, view-script and script-module assets for nested blocks are enqueued as needed.

### `porter_get_template_part( $base, $post_type = '', $suffix = '' )`

Returns the first existing template-part slug in this order:

1. `{base}-{post_type}-{suffix}`
2. `{base}-{post_type}`
3. `{base}-{suffix}`
4. `{base}`

It returns an empty string when none exists.

```php
$slug = porter_get_template_part(
    'related-posts-card',
    get_post_type(),
    porter_get_template_suffix()
);

if ( $slug ) {
    echo porter_safe_return_template_part( $slug );
}
```

### `porter_get_template_suffix()`

Returns a request-aware suffix such as `single-event`, `archive-event`, `archive-category`, `archive-tag`, `home`, `search`, `404` or `default`. Empty post-type archives are supported; the helper does not depend on a global post object.

### `porter_enqueue_block_assets( $parsed_block )`

Recursively enqueues registered styles, view styles, scripts, view scripts and view-script modules for a parsed block tree. Use this when rendering parsed blocks outside WordPress's usual block-render path.

## Query and configuration helpers

### `porter_get_custom_post_types( $public_only = true, $return = 'slug' )`

Returns post-type slugs from `posttypes.json`, always including `post`. With `$public_only = true`, entries configured as `admin_only` are omitted. Pass `'object'` as the second argument to receive registered post-type objects.

### `porter_is_tax_term_query( $query, $taxonomy, $term_id )`

Checks both WordPress's native taxonomy conditionals and positive `tax_query` clauses. This is useful when another query integration has converted an archive request into explicit query arguments.

### `porter_get_theme_settings( $path )`

Reads a slash-delimited path from `wp_get_global_settings()`. The shortcut `theme-colors` maps to `color/palette/theme`.

### `get_relative_permalink( $page_id )`

Returns a site's permalink without the home URL or leading/trailing slash.

### `porter_can_use_cached()`

Returns `true` only when `wp_get_environment_type()` is `production`. This governs Porter's reusable configuration and discovery caches; it does not govern the separate short-lived Site Editor preview cache.

## Plugin path helpers

`porter_get_path( $filename )` and `porter_get_url( $filename )` resolve a path or URL inside the PorterWP plugin. They are primarily useful to Porter integrations; themes should use WordPress theme path functions for theme assets.
