• I’ve created a plugin that adds a custom post type of ‘portfolio’ and I currently have to manually add archive-portfolio.php, taxonomy-portfolio.php and single-portfolio.php template files to the theme folder.

    I would like to include everything in the plugin without having to manually create/add these files to the theme folder?

    Can anyone help or advise on a decent tutorial that explains what I need

    thanks in advance ??

Viewing 1 replies (of 1 total)
  • Thread Starter seanuk

    (@seanuk)

    ok, I found this https://codex.www.ads-software.com/Plugin_API/Filter_Reference/single_template and I have added 3 functions to my plugin, one for each archive_template, single_template and taxonomy_template

    is there a way to combine them into one function?

    function get_single_template($single_template) {
         global $post;
         if ($post->post_type == 'portfolio') {
              $single_template = dirname( __FILE__ ) . '/single-portfolio.php';
         }
         return $single_template;
    }
    add_filter( "single_template", "get_single_template" ) ;
    
    function get_archive_template($archive_template) {
         global $post;
         if ($post->post_type == 'portfolio') {
              $archive_template = dirname( __FILE__ ) . '/archive-portfolio.php';
         }
         return $archive_template;
    }
    add_filter( "archive_template", "get_archive_template" ) ;
    
    function get_taxonomy_template($taxonomy_template) {
         global $post;
         if ($post->post_type == 'portfolio') {
              $taxonomy_template = dirname( __FILE__ ) . '/taxonomy-portfolio.php';
         }
         return $taxonomy_template;
    }
    add_filter( "taxonomy_template", "get_taxonomy_template" ) ;
Viewing 1 replies (of 1 total)
  • The topic ‘Adding page templates from a plugin’ is closed to new replies.