How to Add PHP Pages to WordPress Without Using APIs
For those seeking to create custom WordPress pages while incorporating their PHP code, it's possible to achieve this without having to interact with the WordPress API. Here's a step-by-step guide:
-
Duplicate a Theme Template:
- Navigate to the "wp-content/themes/themename" directory and duplicate either post.php or page.php, depending on the type of page you want to create.
-
Rename the New Template:
- Change the filename of the new template to "templatename.php," where "templatename" is your desired name for the template.
-
Add Template Name Declaration:
-
At the beginning of the templatename.php file, add a comment specifying your template's name:
<?php
/*
Template Name: Name of Template
*/
?>
-
Customize Your Template (Optional):
- In the templatename.php file, you can write PHP code to include other files, connect to third-party APIs, or perform any other desired actions.
-
Create a New Page:
- In your WordPress dashboard, create a new page and locate the "Attributes" widget on the right-hand side.
-
Select Your Template:
- From the "Template" dropdown menu in the "Attributes" widget, select your new "Name of Template."
-
Publish Your Page:
- Click "Publish" to save your new page, which will now use the PHP code defined in templatename.php.
The above is the detailed content of How to Add Custom PHP Pages to WordPress Without Using APIs?. For more information, please follow other related articles on the PHP Chinese website!
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn