Creating a custom page in plugin code
-
Some of WordPress’ vocabulary is ambiguous, so I would try to be as precise as I can for my needs. For the lack of better term, I used the word “page” in subject, but I am NOT referring to page (as in a WP page of “page” post type).
We all know WP ships with out of the box post types, e.g. blog and page post types. Both of these are oriented around displaying static content (well a blog post or About page is almost static once created).
I am trying to write a plugin and what I am really wanting to do is to provide a non-post type (i.e. non content type) page from my plugin. Let’s take an example.
Let’s say I want to expose a search form at this url in my WP site:
https://example.com/ad-searchThe page would provide a few search criteria and upon submitting the form, I will execute a search for Active Directory users and list them as a html table on the page.
You would see what I need is just the ability to define a relative url (ad-search) in the plugin, which when opened would invoke code from my plugin which would render the page’s content.I am expecting side-bars etc. to show up normally on this page, just the main page content is totally dictated in my plugin code.
You would see this use-case is not suitable for defining a custom content type (aka custom post type) as there won’t be posts of this content type.
I reckon one way of doing this might be to expose my search-form as a widget, then create a page and embed the widget as content on the page using many ways of embedding widgets in main content area of a page I found after googling.
Although this is an option, I am trying to see if there’s a better and more “pure” way of doing it in WordPress (I am hoping there is one, most CMSes out there these days that have some traction do provide something).
So in a nut-shell, I am trying to create a WP plugin that can create a totally custom form, expose it in WP using a relative url of choice and then be able to handle POST requests from such a form.
I am open to ideas where you think WP has a better way of catering to this scenario than the one already listed (a widget inside a page).
- The topic ‘Creating a custom page in plugin code’ is closed to new replies.