Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am working on a WP theme/project that includes several custom page templates that will only be used once each. For example, there is a page with a map and search form for finding things on the map. Clearly the map page needs a unique page template, but that template will never be used for any other pages. I would like to hide or remove this page template from the "Template" drop-down menu, so when the client is selecting page templates they only see options they should select from. Anyone know how to do that, or should I be approaching this from an entirely different angle?

Thanks, Kirkland

++++++++++++++++

UPDATED - Solution:

For each of the page templates that I wanted to use one time only (ie: during setup, before the client had access) I simply removed...

/*
Template Name: NAME_HERE
*/

So that it wouldn't show as an option when adding a new page. Then I replaced everything in page.php with this...

if ( is_front_page() ) { include('page-home.php'); }
elseif ( is_page(22) ) { include('page-something.php'); }
elseif ( is_page(48) ) { include('page-whatever.php'); }
else{ include('page-default.php'); }

Everything that was in page.php gets moved to page-default.php. Or you could just put it all inside the else statement at the end. Either way.

This works for me because I will be doing the setup for the client, so I will be creating the "one time only" pages before handing this project off to them - I will know the page IDs.

BTW... You do not need to keep the naming scheme page-XXX.php for this to work. I just did that so I can group them more easily.

I left the "Template Name" comment in the pages I do want the client to be able to select when adding pages (ex: "full width" page-full.php) and did not add a if condition or include to them in page.php.

share|improve this question
    
Add you solution as an answer. –  toscho May 2 '12 at 19:44

1 Answer 1

up vote 3 down vote accepted

If a page won't work without a specific template, I would just remove the need for them to select a template. Filter template_include and select the template based on the requested page:

function wpse50455_template_include( $template ) {
    // check if it's a page
    if ( is_page() ):
        $this_page_id = get_query_var( 'page_id' );
        // check for presence of meta data to determine what template you need
        // return the desired template if required
        return get_stylesheet_directory_uri() . '/my-special-template.php';
    endif;

    return $template;
}
add_filter( 'template_include', 'wpse50455_template_include' );
share|improve this answer
    
You get the points for being the only one to answer before I realized I was overly complicating a simple problem. I added my fix above. –  Kirkland Apr 27 '12 at 20:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.