template-loader.php
Template loader with override hierarchy
Handles template loading for single and archive views with support for:
- Theme overrides (child/parent)
- MU plugin overrides
- Debug templates (when WP_DEBUG is enabled)
- Template partials loading
Tags
Table of Contents
Functions
- jpkcom_acf_references_locate_template() : string|false
- Locate template file with override support
- jpkcom_acf_references_template_include() : string
- Template loader for singular and archive templates
- jpkcom_acf_references_get_template_part() : void
- Load partial templates with full override support
Functions
jpkcom_acf_references_locate_template()
Locate template file with override support
jpkcom_acf_references_locate_template(string $template_name) : string|false
Searches for template files in this priority order:
- Child Theme: /wp-content/themes/your-child-theme/jpkcom-acf-references/
- Parent Theme: /wp-content/themes/your-theme/jpkcom-acf-references/
- MU plugin override: /wp-content/mu-plugins/jpkcom-acf-references-overrides/templates/
- Plugin itself: /wp-content/plugins/jpkcom-acf-references/templates/ (or debug-templates/ if WP_DEBUG)
Parameters
- $template_name : string
-
Template filename (e.g., 'single-reference.php' or 'partials/reference/customer.php').
Tags
Return values
string|false —Full path to template file if found, false otherwise.
jpkcom_acf_references_template_include()
Template loader for singular and archive templates
jpkcom_acf_references_template_include(string $template) : string
Intercepts WordPress template_include filter and loads custom templates for reference, reference_customer, and reference_location post types (single and archive views).
Parameters
- $template : string
-
Default template path from WordPress.
Tags
Return values
string —Template path to use (plugin template or default).
jpkcom_acf_references_get_template_part()
Load partial templates with full override support
jpkcom_acf_references_get_template_part(string $slug[, string $name = '' ][, array<string|int, mixed> $args = [] ]) : void
Similar to WordPress get_template_part() but uses the plugin's template hierarchy system. Useful for loading reusable template partials.
Example usage: jpkcom_acf_references_get_template_part('partials/reference/customer'); jpkcom_acf_references_get_template_part('partials/reference/customer', 'detailed'); jpkcom_acf_references_get_template_part('partials/reference/modal', '', ['data' => $data]);
Parameters
- $slug : string
-
Template slug (e.g., 'partials/reference/customer').
- $name : string = ''
-
Optional. Template name/variation (e.g., 'alternative'). Default empty.
- $args : array<string|int, mixed> = []
-
Optional. Array of variables to pass to the template. Default empty.