i hade create a new template in my plugin code

add_filter( 'template_include', 'bogin_page_template', 99 );

function bogin_page_template( $template ) {

if ( is_page( 'bog_test' )  ) {
    $new_template = locate_template( array( 'bog_test.php' ) );
    if ( !empty( $new_template ) ) {
        return $new_template;

return $template;


and i created a file bog_test.php in my plugin directory. but when i go to http://bogss.co.il/bog_test/ it says page not found. what am i missimg here ? thank you !

  • Have you actually created a page called 'bog_test'? – Jacob Peattie May 15 '18 at 11:51
  • yes, in the same dir as my plugin.php file(duffrent name for the plugin file..) – bogin May 16 '18 at 12:57
  • That doesn’t make any sense. Pages aren’t files in plugins or themes. They’re added in the WordPress backend. Also, locate_template won’t work for a template file in a plugin. It searches themes. – Jacob Peattie May 16 '18 at 18:10
  • ok, so how can i add a page to a store with a plugin ? – bogin May 17 '18 at 9:54

Actually you can overwrite get_page_template() using page_template filter. So now, your code should be like bellow code.

   add_filter( 'page_template', 'load_template_from_plugin' );
   function load_template_from_plugin( $page_template ){
        if ( is_page( 'bog_test' ) ) {
            $page_template = dirname( __FILE__ ) . '/bog_test.php';
        return $page_template;

Try the above code then let me know the result. Thanks

| improve this answer | |
  • ok, so i paste it in my plugin code, and then did some stuff with the plugin to make sure it run's the code, but still the resuls is "page not found. so i tried bogss.co.il/bog_test.php and bogss.co.il/bog_test both not good. what am i miising here? mybe the bog_test.php need somting to be wirtten in it ? – bogin May 16 '18 at 13:04

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.