0

I'm developing a Wordpress plugin and I want to create a file to where I want to redirect the user to show some information. I know that a perfect solution for this is using Wordpress custom pages. I've used it in the past and it was very useful. The problem is I can not use custom pages in my plugin. I was wondering if there is any other way to do the same thing we do with pages inside a theme, but inside a plugin. Does anyone know anything that can help with this issue? Thanks a lot

1

You will create a page template whose file name is custompage-template.php here I suppose put in in your plugin dir/views/ folder. Whenever the page whose title is Your Page Name is visited, the site will render your custom template

add_filter( 'page_template', 'fw_reserve_page_template' );
function fw_reserve_page_template( $page_template )
{
    if ( is_page( 'Your Page Name' ) ) {

        $page_template = dirname( __FILE__ ) . '/views/custompage-template.php';
    }
    return $page_template;
}

Put it in your plugin file.

  • There is a bug in your code. This will fail if the template is not found as there is no fall back for it :-) – Pieter Goosen Jul 23 '15 at 6:44

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.