Create 'virtual' page that doesn't show up in backend

(Alex P) #1

I’m looking for a way to automatically create a page, with a custom view/template, that doesn’t show in wp-admin/backend. I think I’ve seen that done by some plugins, but I don’t know how to start.

Currently, what I do is create a custom page template, but I also have to add a new page within wp-admin – even if that page will never be edited by back-end as the_content() is not needed. Could I skip this?

(Ben) #2

You could use custom rewrite rules to generate custom pages, but that may be a bit complex for something like this.

You may also be able to create the page in the admin and then use a filter to hide the page from the admin.


If you’d explain why you want to set it up like this, you’d probably get more advice.

I use CPTs without the_content all the time, so the answer to your question is, yes, it is possible, but unless we know why you are doing it, we don’t know the alternative you are looking for.

(Alex P) #4

The why could be many reasons, any case where I need a page that doesn’t need editing in the back-end, it could be a specific type of custom archive, an api endpoint etc.
In the meantime I found out that just googling wordpress virtual pages (via) takes me on the right path.

@BinaryMoon – that’s sort of what I’m (still) doing at the moment, creating pages manually, and using just the slug, for a custom page template. Of course, I could also do this from code, so I don’t have to manually add a page for each instance – that was my first thought, but I’ve seen plugins having custom views/slugs, and this is the more elegant way.

(Anh Tran) #5

There are some ways to do that. And custom rewrite rules are not as complicated as you thought :).

I wrote an article on this topic that covers at least 3 methods.

Hope that helps.