astra_addon_locate_template( string $template_name, string $template_path = '', string $default_path = '' )

Locate a template and return the path for inclusion.


Description

This is the load order:

 yourtheme       /   $template_path  /   $template_name  yourtheme       /   $template_name  $default_path   /   $template_name

Parameters

$template_name

(string) (Required) template path. E.g. (directory / template.php).

$template_path

(string) (Optional) (default: '').

Default value: ''

$default_path

(string) (Optional) (default: '').

Default value: ''


Return

(string) return the template path which is maybe filtered.


Source

File: classes/class-astra-templates.php

	function astra_addon_locate_template( $template_name, $template_path = '', $default_path = '' ) {

		if ( ! $template_path ) {
			$template_path = 'astra-addon/';
		}

		if ( ! $default_path ) {
			$default_path = ASTRA_EXT_DIR . 'addons/';
		}

		/**
		 * Look within passed path within the theme - this is priority.
		 *
		 * Note: Avoided directories '/addons/' and '/template/'.
		 *
		 * E.g.
		 *
		 * 1) Override Footer Widgets - Template 1.
		 * Addon: {astra-addon}/addons/advanced-footer/template/layout-1.php
		 * Theme: {child-theme}/astra-addon/advanced-footer/layout-1.php
		 *
		 * 2) Override Blog Pro - Template 2.
		 * Addon: {astra-addon}/addons/blog-pro/template/blog-layout-2.php
		 * Theme: {child-theme}/astra-addon/blog-pro/blog-layout-2.php.
		 */
		$theme_template_name = str_replace( 'template/', '', $template_name );
		$template            = locate_template(
			array(
				trailingslashit( $template_path ) . $theme_template_name,
				$theme_template_name,
			)
		);

		// Get default template.
		if ( ! $template || ASTRA_EXT_TEMPLATE_DEBUG_MODE ) {
			$template = $default_path . $template_name;
		}

		// Return what we found.
		return apply_filters( 'astra_addon_locate_template', $template, $template_name, $template_path );
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.


User Contributed Notes

You must log in before being able to contribute a note or feedback.