How to add a PHP page to WordPress?

WordPress is one of the best blogging platforms. This is the scenario, we have a custom PHP page which we want to integrate with the WordPress blog. Our PHP file which we are getting to integrate might not use any of the WordPress APIs. Integrating PHP files with WordPress is very important for the back-end development of web design.

Step 1: Login to Microsoft Web Matrix 
The following screen appears. Open or create your WordPress template.

Step 2: Create WordPress Template Page 
We can start with a sample file and copy page.php, rename it on your choice and put it inside the theme folder ../wp-content/themes/mytheme/

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
/*
Template Name: GFG
*/
  
/* Rest PHP code here */
?>

chevron_right


This new file should start with the following content and then followed by the custom PHP content. This is the WordPress template. 
Remember to upload this to the theme folder. Now the WordPress template is ready.

Step 3: Create WordPress Page
Click the “Pages” link from the WordPress Dashboard. The template we created can be used to create this new page. We can give the Page name and choose the “Template” from the drop-down from the “Page Attributes” section. There the PHP-page we uploaded will come with the “GeeksfoGeeks” listed in the dropdown. Now publish. Here we go, we have created a WordPress PHP page using our custom code. Whenever this page is linked, our custom PHP code will get executed. Various types of templates can be created through it.



Example: In functions, you need to implement it as follows:

filter_none

edit
close

play_arrow

link
brightness_4
code

function simple_function_1() {
    return "Hello World!";
}
  
add_shortcode( 'own_shortcode1', 'simple_function_1' );

chevron_right


In post/page:

[own_shortcode1]

Output:

Hello World!

A real-time scenario is we will construct a sitemap page using this WordPress template option.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.