How to add PHP coded page in WordPress?

Photo of author
Written By geekerhub

Lorem ipsum dolor sit amet consectetur pulvinar ligula augue quis venenatis. 

As a developer, we come across the scenario that we are just using the core PHP code while developing a specific requirement page.

In such a case, beginner gets confused that how to do core PHP development for the WordPress page?

To write PHP code for the specific WordPress page that interacts with third party API, you can achieve this using:

  • Create a single page File
  • Creating a Template File
  • Creating a Shortcode

The best and easy solution to start with is Template File. Create a templatename.php file under /wp-content/themes/themename/ (where templatename is what you want to call your new template).

To add your new template to the list of available templates, enter the following at the top of the new file which will be visible for the specific given post types in WordPress.

Template Name: Name of Template
Template Post Type: post, page, event
// code here...

You can modify this file (using PHP) to include other files or whatever you need.

Then create a new page in your WordPress blog, and in the page editing screen, you’ll see a Template dropdown in the Attributes widget to the right.

Select your new template and publish the page. Your new page will use the PHP code defined in templatename.php

Leave a Comment