Return to Snippet

Revision: 63611
at May 22, 2013 01:34 by bitsculptor


Initial Code
add_filter( 'page_template', 'wpa3396_page_template' );
function wpa3396_page_template( $page_template )
{
    if ( is_page( 'my-custom-page-slug' ) ) {
        $page_template = dirname( __FILE__ ) . '/custom-page-template.php';
    }
    return $page_template;
}

Initial URL
http://wordpress.stackexchange.com/questions/3396/create-custom-page-templates-with-plugins

Initial Description
This allows you to create a custom page template in your plugin. Say your plugin creates a custom post type and you want to override the standard archives page template to display your custom post type in a special way. You could achieve this by creating a custom template for your post type and using this code to display that template when appropriate.

Initial Title
Custom Page Templates in a WordPress Plugin

Initial Tags
plugin, wordpress

Initial Language
PHP