Wordpress Site Php File

Active5 months ago

I want to create a custom page for my WordPress blog that will execute my PHP code in it, whilst remaining a part of the overall site CSS/theme/design.

  1. The 'WordPress Address (URL)' setting is the address where your WordPress core files reside. It is possible to set the site URL manually in the wp-config.php file.
  2. Unlike other files, wp-config.php file does not come built-in with WordPress rather it’s generated specifically for your site during the installation process. WordPress stores your database information in the wp-config.php file.
  3. Wp-config.php: Deleting this file of a WordPress installation would trigger the WordPress installation process on the next visit to the website.

The PHP code will make use of 3rd party APIs (so I need to include other PHP files)

How do I accomplish this?

N.B. I do not have a specific need to interact with the Wordpress API - apart from including certain other PHP libs I need I have no other dependencies in the PHP code I want to include in a WP page. So obviously any solution that didn't require learning the WP API would be the best one.

Volker E.
4,52610 gold badges38 silver badges62 bronze badges

The best way to add custom code to your WordPress site is by adding it to functions.php file of your child theme or by creating a site-specific plugin. WordPress stores all your image and media uploads in the /wp-content/uploads/ folder. * Handle PHP uploads in WordPress, sanitizing file names, checking extensions for mime type, * and moving the file to the appropriate directory within the uploads directory. * @access private. Jul 28, 2017  Unless you're a web developer, you probably aren't aware of the fact that your WordPress website is using PHP. However, if you want to improve your site's security and performance, it's a good idea to familiarize yourself with PHP and learn how to check your WordPress site’s PHP Version.

rutherfordrutherford
4,28012 gold badges41 silver badges68 bronze badges

18 Answers

You don't need to interact with the API or use a plugin.

First, duplicate post.php or page.php in your theme folder (under /wp-content/themes/themename/).

Rename the new file as templatename.php (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:

Apr 22, 2018  PHP Tools for Visual Studio - gateway. I clear the regedit of this tools, and License key never show when open the VisualStudio 2013. After 1 hour of searching i didn't found a patch for PHP Tools v1.24. (Visual Studio 2017), then i decided to make mine. Never had such a great debugging experience with PHP and Visual Studio. God thanks there is PHP tools, so I have all my favourite languages within my favourite IDE! Marco Klein Student. Php tools for visual studio license key With a purchased license key, you may activate your copy of PHP Tools for Visual Studio. The product can be activated from the Visual Studio menu. The product can be activated from the Visual Studio.

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

Source: https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-custom-page-templates-for-global-use

Meetai.com
4,6533 gold badges26 silver badges30 bronze badges
Adam HopkinsonAdam Hopkinson
23.8k5 gold badges50 silver badges80 bronze badges

If you wanted to create your own .php file and interact with Wordpress without 404 Headers and keeping your current permalink structure there is NO Need for a Template file for that 1 page, I found that this approach works best, in your .php file:

Than you can simply perform any wordpress functions after this. Also, this assumes that your .php file is within the root of your wordpress site where your wp-config.php file is located.

This, to me, is a PRICELESS discovery as I was using require_once(dirname(__FILE__) . '/wp-blog-header.php'); for the longest time as Wordpress even tells you that this is the approach that you should use to integrate Wordpress Functions, cept, it causes 404 headers, which is weird that they would want you to use this approach. https://codex.wordpress.org/Integrating_WordPress_with_Your_Website

I know many people have answered this question and it already has an accepted answer, but here is a nice approach for a .php file within the root of your wordpress site (or technically anywhere you want in your site), that you can browse to and load without 404 Headers!

EDIT

Just a quick update here. There is a way to use wp-blog-header.php without 404 headers, but this requires that you add in the headers manually, something like this will work in the root of your wordpress install:

Just to update you all on this, a little less code needed for this approach, but it's up to you on which 1 you use.

Solomon ClossonSolomon Closson
2,67810 gold badges47 silver badges88 bronze badges

If you're like me, sometimes you want to be able to reference WordPress functions in a page which does not exist in the CMS. This way, it remains backend specific and cannot be accidentally deleted by the client.

This is actually simple to do just by including the wp-blog-header.php file using a php require().

Here's an example that uses a query string to generate Facebook OG data for any post.

Take the example of a link like http://example.com/yourfilename.php?1 where 1 is the ID of a post we want to generate OG data for:

Now in the contents of yourfilename.php which, for our convenience, is located in the root WP directory:

There you have it: generated sharing models for any post using the post's actual image, excerpt and title!

We could have created a special template and edited the permalink structure to do this, but since it's only needed for one page and because we don't want the client to delete it from within the CMS, this seemed like the cleaner option.

E-card Website Greeting Card Site Php Script

EDIT 2017:Please note that this approach is now deprecated

For WP installations from 2016+ please see https://stackoverflow.com/a/39800534/1958998 for extra parameters to include before outputting your page data to the browser.

DrewTDrewT
3,9182 gold badges31 silver badges47 bronze badges

Creating the template page is the correct answer, for this just add this into the page you created inside the theme folder

For running this code , you need to select mytemplate as template of the page from the back end

please see this link for to get the correct details https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/.

Surveying programs book hp 33s calculator. Many land surveyors still like the convenience of a pocket calculator in the field. They are trusty, don't create many of the problems found in many modern day calculators and most of all, there are many surveyors who completed school and were taught surveying using calculators.

user5742826

Any answer did not cover if you need to add a PHP page outside of the WordPress Theme. This is the way.

You need to include wp-load.php.

Then you can use any WordPress function on that page.

I am the Most Stupid PersonI am the Most Stupid Person
3603 gold badges9 silver badges34 bronze badges

The widely accepted answer by Adam Hopkinson is not a fully automated method of creating a page! it requires a user to manually create a page in the back-end of WordPress (in the wp-admin dash). The problem with that is, a good plugin should have a fully automated setup, it should not require clients to manually create pages.

Also, some of the other widely accepted answers here involve creating a static page outside of WordPress, which then include only some of the WordPress functionality to achieve the themed header and footer. While that method may work in some cases, this can make integrating these pages with WordPress very difficult without having all its functionality included.

I think the best, fully automated, approach would be to create a page using wp_insert_post and have it reside in the database. An example and a great discussion about that, and how to prevent accidental deletion of the page by a user, can be found here: wordpress-automatically-creating-page

Frankly, I'm surprised this approach hasn't already been mentioned as an answer to this popular question (it has been posted for 7 years).

Damian GreenDamian Green
4571 gold badge5 silver badges13 bronze badges

Create a page call it my-page.php and save it under your theme directory.Now, edit this php file and write the following line at the top of the page

Write your PHP code under the custom page definition line, you can call your other WP template, functions inside this file.

Start like <?php require_once('header.php');?> OR

whatever way you are integrating your header and footer to keep the layout consistent.

Since this is a my page, you NEED TO CREATE A PAGE from WordPress admin panel.Go to Admin => Pages => Add New

Add a page title, depending upon how you have coded the custom page, you might add page body (description) as well. You can fully skip the description if it’s written in the custom php page.

At right hand side, select Template.Choose My Custom Page from the dropdown.You are all set! Go to the slug (permalink) created by [wordpress][1] and see the page.

Inder
2,2516 gold badges13 silver badges26 bronze badges
ashish thakorashish thakor

You will want to take a look in to WordPress' plugin API. This explains how to 'hook' and 'filter' in to different parts of the WordPress mechanics, so you can execute custom PHP code pretty much any where at any given time. This hooking, filtering, and custom code authoring can all take place in your functions.php file in any of your themes. Happy coding :)

hsatterwhitehsatterwhite
3,6093 gold badges22 silver badges29 bronze badges

If you don't want to deal with WP API, then Adam's answer is really the best one.

If you were willing to deal with the API I would suggest hooking into the 'template-redirect' hook, which would allow you to point a particular URL or page to an arbitrary PHP file while still having access to the WP.

Stephen RStephen R
1,2491 gold badge8 silver badges24 bronze badges

Apart from creating a custom template file and assigning that template to a page ( like in the example in accepted answer ), there is also a way with template naming convention that Wordpress uses for loading templates ( template hierarchy ). Create a new page and use the slug of that page for template filename ( create template file named page-{slug}.php ). WordPress will automatically load the template that fits to this rule.

DanijelDanijel
10.3k3 gold badges27 silver badges47 bronze badges
Heena PatelHeena Patel

Rename the new file as templatename.php (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:

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.

Nirav WebbleuNirav Webbleu

just create a page-mytitle.php to the folter of current theme, and from the Dashboard a page mytitle. Then when you invoke the page by the url you are going to see the page-mytitle.php. You must add htmp, css, js wp-loop e.t.c to this php file (page-mytitle.php)

Elias KatsaniotisElias Katsaniotis

You can create the template in Theme Folder than after place your php code in that template file.If You will be required some files for that than you can include that files in that template.See below.

ayaio
61.2k20 gold badges138 silver badges202 bronze badges
Mehul SoniMehul Soni

The best way to add PHP pages in WordPress to Page Template in the child-theme folder.

How to create Page Template in WordPress.

Create a file named template-custom.php and put it in /wp-content/theme/my-theme/.

How To Login In Site Php Has Sql Inject

Gufran HasanGufran Hasan
3,8255 gold badges18 silver badges31 bronze badges

You can name your file newpage.php - put it in your theme directory in wp-content. You can make it a page template (see http://codex.wordpress.org/Pages..) or you can include it in one of the php files in your theme, such as header.php or single.php. Even better, create a child theme and put it in there, so you leave your theme code alone and it's easier to update.

Chandra KumarChandra Kumar
3,3171 gold badge8 silver badges20 bronze badges
Ahmed ElcheikhAhmed Elcheikh

You can also directly use the php page, like to create the php page and run with full path. like, http://localhost/path/filename.php

nimnim

Creer Un Site Php Debutant

Not the answer you're looking for? Browse other questions tagged phpwordpress or ask your own question.

Comments are closed.