Skip to content

Instantly share code, notes, and snippets.

@pelmered
Created June 12, 2015 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pelmered/b73b40dd024d299ccf81 to your computer and use it in GitHub Desktop.
Save pelmered/b73b40dd024d299ccf81 to your computer and use it in GitHub Desktop.
Allow template to override plugin templates
function include_template( $template, $args = array() )
{
//Allow plugins to manipulate the tempalte data before sending it to the template
$data = apply_filters('prefix_template_data', $args, $template);
//Look in theme folder first, then plugin folder
if(locate_template($template) === '')
{
include PREFIX_PLUGIN_PATH . 'templates/' . $template;
}
else
{
include locate_template($template);
}
}
//Usage
$args = array(
'my' => 'template_data',
'foo' => 'bar'
)
$template_name = 'plugin-template-filename.php';
include_template( $template, $args );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment