I have implemented inside my plugin this hook to change the single template for custom post type (I do not want it to be in the child theme, just in my plugin) and it works just fine.

Now I want to implement content-single.php inside my plugin. How can it be done? This is the code that implements the custom template inside the plugin:

//Template fallback
function get_custom_post_type_template($single_template) {
    global $post;
    if ($post->post_type == 'my-custom-post-type') {
        $single_template = dirname( __FILE__ ) . '/single-my-custom-post-type.php';
    return $single_template;
add_filter( 'single_template', 'my-custom-post-type' );
  • Do you mean that you have a custom single-content.php in your plugin that you wish to use, or that you want your plugin template to use the default content-single.php? If it's the first, look at locate_template(), if it's the second look at get_template_part(). If it's neither, please can you clarify. – David Gard Feb 3 '15 at 10:18
  • I am already load single_template and this is fine. But I would like to make custom template for the content itself (the title, body and the other parts of the custom post type). – Dori Feb 3 '15 at 14:21
  • Have a look at any of the default ones to see how they are done, there are plenty available in the twentyfourteen and twentyfifteen themes. – David Gard Feb 3 '15 at 16:02

In case anyone will want to do this, this is what worked for me:

In my single-my_custom_post_type.php

I replaced this line:

get_template_part('content', get_post_format());

With this one:

include 'content-spp_service_provider.php';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.