2

This idea is just to protect certain sections of my theme from over-zealous clients. I would like to add pages, that exist in the front end and can be added to the menu (using wordpress 3.0 api) but the page NOT be present in the 'Pages' dialogue in the admin panel, and is thus not user editable.

3
  • This question is a little bit vague. Could you clarify please? Sep 27, 2010 at 16:00
  • What I mean, I want to call a template file without assigning that you a page.
    – Mild Fuzz
    Sep 27, 2010 at 16:39
  • For example, I have a section that lists venues. It is a loop based on the custom post type, 'Venus'. I have a template file with that loop, but in order to put that page in the navigation, I have to assign the template to a page. Can I avoid this?
    – Mild Fuzz
    Sep 27, 2010 at 16:40

1 Answer 1

3

You can hook into template_redirect like this:

function custom_template_redirect() {
    global $wp;

    if ($wp->query_vars['pagename'] == 'my-page-slug') { // check the page slug
        status_header(200); // a 404 code will not be returned in the HTTP headers if the page does not exists

        include(TEMPLATEPATH . "/test.php"); // include the corresponding template
        die();
    }
}
add_action( 'template_redirect', 'custom_template_redirect' );
2
  • Does this mean I still need to have a page in the pages DB in order to have a nav link?
    – Mild Fuzz
    Sep 28, 2010 at 8:43
  • 1
    Yes, you will need to have the page in the db, or you can hook into the filter 'wp_nav_menu_items' or "wp_nav_menu_{$menu->slug}_items" with a custom code to add the page in the nav.
    – sorich87
    Sep 28, 2010 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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