Open In App

How to add a PHP page to WordPress?

Improve
Improve
Like Article
Like
Save
Share
Report

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/




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


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:




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


In post/page:

[own_shortcode1]

Output:

Hello World!

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


Last Updated : 05 Aug, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads