0

I have inside a theme two important static pages. One is a confirmation page (after signing up for a newsletter) and the other one is a thank-you page.

I am using these in various functions and create them upon theme install with predefined content.

The problem is some users tend to change the slug, or the title of the page.

I am currently using get_page_by_title but that doesn't work once the title is changed. I have a fall back that the user can define inside an options panel which one is his confirmation page but I really don't like this solution. The other problem is that once the title is changed my page template (for example page-confirm.php) doesn't get apply automatically neither, so the user has to choose it as well.

Is it possible to create fixed static pages that don't show up inside "Wordpress Pages"? Like a static page for internal use only?

  • I would try something like pre_get_posts filter with condition Is it admin Pages list? Than exclude posts with ID 4, 5 and 25. So those pages will never show in Page list ... but I don't know if it is bulletproof solution. – Marek Aug 21 '15 at 9:18
1

I would not try to get too tricky and hide pages from users. What happens if they try to create a page with the same slug? I think it would just create confusion and more problems than it would solve.

When you create the pages, store their IDs, not slug. Let users then change those through your options screen. This is similar to how WordPress tracks your blog and front page- by storing their IDs in options.

Then for the templates, add a filter to page_template and apply your custom templates if the ID of the requested page matches what's stored in the option.

  • Thanks Milo, you are right I decided that it won't be a good idea to hide these pages. I catched upon the creation of the pages the ID, stored it in the database and use this page ID within all functions that need to know these pages. The user can freely edit the slug or title, the only thing he shouldn't do is to delete them. – Snowball Aug 21 '15 at 17:09
0

You could create a custom post type of "Static Pages" that do not allow you to update the titles.

remove_meta_box( 'post_title' , 'your_custom_post_type', 'normal' );
remove_meta_box( 'slugdiv' , 'your_custom_post_type', 'normal' );

Then add in your static pages programmatically with wp_insert_post(); and force the slug and post_title to what you want.

It is not an ideal approach, but could give you more control over the pages. You may want to tweak the capabilities for that custom post type also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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