Check if a template is in use

This snippet is collected from a plugin, to check if the theme folder has a xyz.php file, if not, then the xyz.php from the plugin is loaded.

if ( $archive_template === get_stylesheet_directory() . '/' . $template_name ) {
                return $archive_template;
            }

return plugin_dir_path( __FILE__ ) . 'templates/' . $template_name;

 

Leave a Reply

Your email address will not be published. Required fields are marked *