5

Does anyone know if it's possible to use a page template on a URL, even if a page doesn't exist for that page?

When building sites, I create the relevant pages to ensure use of the templates, but then if the site admins later delete that page, it breaks the site.

I'v read that it's possible to add custom URL rewrites, but is there a way to create a custom URL, but use a regular page template to render up the content (using get_header/footer() & other functions within the page)?

5
  • 1
    what's the actual page content? if the page technically doesn't exist, what does the loop output?
    – Milo
    Mar 14, 2013 at 21:38
  • Good question, from the back of my head I'd say this is not that straight forward to achieve, at least some code is involved because by default Wordpress selects the templates based on the content-type.
    – hakre
    Mar 14, 2013 at 22:01
  • have a look at this post for a potential solution, but it's not so simple to pull off. you'll have a whole bunch of functions to contend with that expect some sort of actual queried object.
    – Milo
    Mar 14, 2013 at 22:06
  • I think you're doing it the right way already. Tell them not to delete the page. :)
    – sam
    Nov 18, 2013 at 6:18
  • How do these pages look like? What is their content? Could you describe such page? Nov 19, 2013 at 21:20

1 Answer 1

1

What I would advice, and have done myself when making WordPress sites for clients. Create a custom post type that they can’t get access to. You can achieve this by conditionally removing the post type from the admin sidebar. One of the ways to solve that problem is to add a custom capability to the user(s) that you would like to allow editing these critical pages, lets call the capability "edit_ciritical_page" Then in your function.php/file included from function.php/plugin file you say

if (!current_user_can("edit_ciritcal_page") {
    remove_menu_page('edit.php?post_type=critical_post_type');
}

If you don’t what to add the custom capability, you could also just check it based on the username/user email.

2
  • Interesting work around. Thanks for the suggestion.
    – TobyG
    Nov 25, 2013 at 16:24
  • By the way, this is indeed secure enough. If one removes a menu page, the user will get "You do not have the permission to access this page" if they do try to access it. Dec 15, 2013 at 3:51

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.