• If I want to make extra custom templates for my theme, is it possible to put it in a subdirectory within the theme directory to reference it?

    So if the code at the top of a custom page were this:

    <?php
    /*
    Template Name: Snarfer
    */
    ?>

    how would I reference that if I were to put snarfer.php inside a directory named “extra-templates”?

Viewing 5 replies - 1 through 5 (of 5 total)
  • You can easily put .php files in subdirectories and call them using get_bloginfo('template_url').'/subdirectory/somefile.php'. I don’t know if WP will recognize a template file if you put it in a subdirectory. Have you tried that?

    Thread Starter onethousandseas

    (@onethousandseas)

    Yep, I put it inside a subdir, but it didn’t work when I simply tried to call it through the control panel.

    I wish it were possible to put custom page templates in a subdirectory, and still choose them in the “Template” <select> box from “Edit Pages” in the admin panel. It would keep the template’s folder a lot cleaner when using a lot of custom page templates.

    It would also be nice if you could keep your stylesheet(s) in their own “./css/” directory.

    Re: kvcrawford – I couldn’t agree more…my theme directory is a mess, and I’ve resorted to just trying to name everything to keep them together (i.e. pg_xx.php so all my custom page templates get alphabetized next to each other, etc)

    A simple solution this is to use the template_redirect hook, and call a function in which you to load your templates from wherever you want, i.e.

    add_action('template_redirect', 'template_overrides');
    function template_overrides()
    {
        if( is_page('potd') ):
           include(HOMEPATH . '/potd_/potd.php');
           exit;
    
        //fallthrough to default
        endif;
    }

    ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Referencing a subdirectory in a custom page template?’ is closed to new replies.