Custom Page Templates in a WordPress Plugin


/ Published in: PHP
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. add_filter( 'page_template', 'wpa3396_page_template' );
  2. function wpa3396_page_template( $page_template )
  3. {
  4. if ( is_page( 'my-custom-page-slug' ) ) {
  5. $page_template = dirname( __FILE__ ) . '/custom-page-template.php';
  6. }
  7. return $page_template;
  8. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.