single_template filter (1 post)

  1. David
    Posted 5 years ago #

    I have made a schedule/event plugin and I want to use my own template page to load when the plugin is activated. I have it so the page is created by the plugin already using wp_insert_post. Now I want to use my own template for that page so I am trying to use the single_template filter method and I am having no luck. It works on post , but for some reason not my pages. Here is the code from the sample page from wordpress.org that I have been using.

    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 tried changing the if statement to check for is_page('my-new-page') but does not work. However it does work if I use is_single('post-name') and click in a post that I made it finds the template ok....just not when I try it for my new page that the plugin made.
    I also have the page template in my plugins directory folder pluginpath/myplugin/templates/mypagetemplate.php.

    Any help would be greatly appreciated or any other workaround to display this new template page.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.