Learn how to add a PHP page to WordPress step by step

How to Add a PHP Page to WordPress

If you use WordPress, you may want to add a custom PHP page. This helps you run your own code, connect APIs, or build tools inside your website.

The best part is you can do this without breaking your site design. In this guide, you will learn simple ways to add a PHP page in WordPress.


Why Add a Custom PHP Page?

You may need a PHP page for many reasons:

  • Connect third-party APIs
  • Run custom scripts
  • Build tools like calculators
  • Show dynamic data
  • Create custom landing pages

For example, if you want to build tools like a CTR calculator, this method is very useful.

πŸ‘‰ Try our tool here: CTR Calculator


Method 1: Create a Custom Page Template (Best Method)

This is the easiest and safest way. It keeps your theme design and works well with WordPress.

Step 1: Open Theme Folder

Go to your theme folder:

/wp-content/themes/your-theme/

Step 2: Copy a File

Copy page.php and rename it:

custom-template.php

Step 3: Add Template

Name

<?php
/*
Template Name: Custom PHP Page
*/
?>

Step 4: Add Your PHP

Code

<?php
/*
Template Name: Custom PHP Page
*/
get_header();
echo "Hello, this is my custom PHP page";
include('my-api-file.php');
get_footer();
?>

Step 5: Create a

Page

Go to WordPress Dashboard β†’ Pages β†’ Add New.

Select the template β€œCustom PHP Page” and publish it.

Now your PHP page is live.


Method 2: Create a PHP File Outside Theme

This method is useful if you want a simple standalone file.</p>

Step 1: Creat

e File

custom-page.php</pre>

Step 2: Load Wor

dPress
<?php
require_once('wp-load.php');
?>
</pre>

Step 3: Ad

d Code
<?php
require_once('wp-load.php');

echo site_url();
?>

This lets you use WordPress functions inside your PHP file.


3: Use Shortcode

This method allows you to run PHP inside a page using a shortcode.

Add Code in functions.php

function my_custom_code(){
    ob_start();
    include('custom-file.php');
    return ob_get_clean();
}
add_shortcode('mycode', 'my_custom_code');

Use in Page

[mycode]

This is great for tools and widgets.


4: Use Page Slug Template

WordPress automatically loads templates based on page slug.

If your page slug is:

my-tool

Create file:

page-my-tool.php

WordPress will load it automatically.


Common Mistakes to Avoid

  • Do not edit WordPress core files
  • Avoid unsafe PHP plugins
  • Always secure your API data

SEO Tip: Add Internal Links

Internal linking helps your website rank better.

Example:

Use these links naturally inside your content.


Best Use Cases

  • SEO tools
  • API integrations
  • Affiliate tools
  • Quote generators
  • Custom dashboards

Conclusion

Adding a PHP page in WordPress is simple if you follow the right method.

The best option is using a custom page template. It keeps your design safe and works smoothly.

If you want to build tools or sell plugins, this method will help you a lot.

πŸ‘‰ Explore our plugins here: View Plugins

Leave a Reply

Your email address will not be published. Required fields are marked *