0

I am working on making a custom post type plugin for my website. However, I want to make it universal for any theme I may decide to change. Or to be able to append the post type to a single post file already.

It's a press release post type, and I am unable to find any guide to how to append or create a universal template file for the single post file.

Any guides or help would be much appreciated.

1

There re various filters you can use to inject your custom template. One being the template_include, the other single_template, and even type_template.

The easiest one would be single_template in your case (example from codex):

function get_custom_post_type_template($single_template) {
     global $post;

     if ($post->post_type == 'my_post_type') {
          $single_template = dirname( __FILE__ ) . '/post-type-template.php';
     }
     return $single_template;
}
add_filter( 'single_template', 'get_custom_post_type_template' );
  • I have that part already. I am trying to find a basic 'single.php' that would work with any theme or how to add the parts I am needing for the post to appear on any 'single.php' before the content and after the content. – xensor Jan 4 at 2:46

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.