0

I looked at some answers and didn't help

I'm trying the next section (right away) but it returns the template if errors in WordPress's built-in function lines. Like get_header ()

add_filter('template_include', 'my_custom_template');

function my_custom_template($single) {

global $post;

/* Checks for single template by post type */
if ( $post->post_type == 'simulators' ) {
        return SIMULATOR_URI . 'inc/themes/admin/single-simulators.php';
    }

return $single;

}

Basically, the template is already listed in WordPress templates, is there an easy way to set it as a custom post template?

  • You don't really need that custom code because you could just create single-simulators.php in the root theme folder, and WordPress would use that template when displaying single posts of the simulators type. See the developer docs for more options on single post templates. – Sally CJ Sep 8 at 1:09
  • I want everything to be in the plugin without the need for a theme change – sbc Sep 8 at 1:33
  • Ok, but what's not working in your code? That filter is indeed one way how one can override templates in WordPress theme or plugin. – Sally CJ Sep 8 at 2:02

Your Answer

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

Browse other questions tagged or ask your own question.