• hello,

    I am creating a plugin with a custom post type project.
    In the plugin I put the CPT and the plugin file with the single file

    I wanted to Custom Page Template withing the plugin and it is not loading what code am I missing because when I put it in the theme file it works ad shoes up in the page attributes

    Thanks

Viewing 1 replies (of 1 total)
  • Thread Starter Jean-Charles de Geekarts

    (@jeancharlesme)

    so I found the solution this is the code

    // adds support for single-projet.php
    function get_single_projet_template($single_template) {
         global $post;
    
         if ($post->post_type == 'projet') {
              $single_template = dirname( __FILE__ ) . '/single-projet.php';
         }
         return $single_template;
    }
    add_filter( 'single_template', 'get_single_projet_template' );
    
    // adds support for archive-projet.php
    
    function get_archive_projet_template( $archive_template ) {
         global $post;
    
         if ( is_post_type_archive ( 'projet' ) ) {
              $archive_template = dirname( __FILE__ ) . '/archive-projet.php';
         }
         return $archive_template;
    }
    
    add_filter( 'archive_template', 'get_archive_projet_template' ) ;
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Page Template in a plugin’ is closed to new replies.