WordPress Plugin Boilerplate Templating – where to start

After spending a whole night to figure this out, I’m on the brink of giving up 🙁

I have created a WordPress Plugin based on the WP Starter Plugin (WordPress Plugin Boilerplate). So far, the backend side is working fine but I just can not find a way on how to get the front end templates working.

The plugin is creating a new custom post type (works), but when I am opening the CPT single, it is not using the single templates that I included in the plugin.

It already came with this function:

function proofing_get_template( $name, $location = '' ) {

$template = '';

$locations[] = "{$name}.php";
$locations[] = "/proofing/{$name}.php";
$locations[] = "/templates/{$name}.php";
$locations[] = "/views/{$name}.php";

 * Filter the locations to search for a template file
 * @param   array       $locations          File names and/or paths to check
$locations  = apply_filters( 'proofing_template_paths', $locations );
$template   = locate_template( $locations, TRUE );

if ( empty( $template ) ) {

    if ( empty( $location ) ) {

        $template = plugin_dir_path( dirname( __FILE__ ) ) . 'views/' . $name . '.php';

    } else {

        $template = plugin_dir_path( dirname( __FILE__ ) ) . 'views/' . $location . '/' . $name . '.php';



return $template;

} // proofing_get_template()

I have this hook in my plugin class:

// Single
$this->loader->action( 'proofing-single-content',   $plugin_templates, 'single_proof_content', 25 );

which calls it here in class-templates.php:

 * Includes the single proof content
public function single_proof_content() {

    include proofing_get_template( 'proof-content', 'single' );

} // single_proof_content()

However, it won’t override the default single.php from the theme. What do I have to do to get the single-cpt.php from the plugin loaded?

Thanks in advance for any help! Have a nice easter 🙂

Kind regards.

Read more here: WordPress Plugin Boilerplate Templating – where to start

Leave a Reply

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