Skip to content

Instantly share code, notes, and snippets.

@claudioweb
Last active May 4, 2016 17:21
Show Gist options
  • Save claudioweb/23e95046f59d85e329c9ce716d28471d to your computer and use it in GitHub Desktop.
Save claudioweb/23e95046f59d85e329c9ce716d28471d to your computer and use it in GitHub Desktop.
function para redirecionar templates e singles de um plugin para /templates
define( 'PLUGIN_PATH', plugin_dir_path(__FILE__));
add_action('template_redirect', 'load_template_pluginname');
function load_template_pluginname(){
global $post;
if(get_post_meta($post->ID, 'pluginname_page', true)){
if(locate_template('template-plugin-name.php', false) == ""){
require_once PLUGIN_PATH . '/templates/template-plugin-name.php';
die();
}
}
if(is_singular('plugin-name')){
if(locate_template('single-plugin-name.php', false) == ""){
require_once PLUGIN_PATH . '/templates/single-plugin-name.php';
die();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment