Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a new page to WordPress using a plugin

Tags:

php

wordpress

How does a plugin add a page to the current WordPress theme a given URL?

Sample URL: http://wordpress/plugin-name/start

This page should display a form using that utilizes the current theme.

At the end of the day I'm going to replace the current front-facing WordPress login and registration mechanisms with a custom implementation.

like image 596
leepowers Avatar asked Mar 24 '10 22:03

leepowers


People also ask

How do I add another page on WordPress?

Upon activation, you need to open up the post or page where you want to embed page content. After that, click the 'Plus' add block icon and search for 'Insert Pages'. Then, click on the 'Insert Page' block. Next, you can choose the page you want to embed in the menu on the right hand side of the page.

How do I link a page to my WordPress Plugin?

Creating New Page Links:Click Pages > Add New Page Link. Provide a title and a destination URL. Optionally provide a custom slug, which will be used in creating a local redirect URL. Click Publish.

How do I create a custom page in WordPress?

Go to WordPress Admin Panel > Pages > Add New. You can see the new custom page template listed on the right side. Create a new page and set its template to PageWithoutSidebar. Once done, Publish it.


1 Answers

You want to hook a function to the template_redirect action.

There, you can recognize the special URL(s) you want and then you can load your own template accordingly.

To make it use the existing theme, you can do similar things like a theme would, such as call get_header(), get_footer(), get_sidebar(), etc.

After you've output your page, you'll need to explicitly call exit(); to prevent the normal page output from occurring.

Note: In WordPress 3.0, a better way is to hook to the template_include filter, and have it return the file-include-path to your own template file.

This doesn't require the exit();, so it's more compatible with other plugins.

like image 134
Otto Avatar answered Sep 23 '22 02:09

Otto