0

I have a WordPress site that I need to create a custom PHP page in. The PHP page contains a webservice I need to call. However, when I call the custom PHP page, WordPress intercepts the call and instead displays a 404 page.

How can I work around that so that the custom PHP displays?

Thanks!

JB

==== Here is the htaccess contents. The folder I want to exclude it's contents from is in /web/content/services. The WP install is in /web/content, including the htaccess file.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(services/.*)$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
0

5 Answers 5

1

Step 1: Create Custom php page under wp-content/themes/YOUR_THEME/ folder.
Step 2: Put following code in your created custom page

Suppose, lets consider we created custom.php

Now,

<?php
/*
    Template Name : custom
*/

//Your Code Goes Here.
echo "<h1>My Custom Page</h1>";

?>

Step 3: Login to your admin panel i.e. wp-admin/
Step 4: Create Page by clicking create page menu located at the left side.
Step 5: Put title of page e.g. My Custom Page.
Step 6: Select Template theme located at the right side. i.e. custom
Step 7: Save the page.
Step 8: Browse page by putting following url.

http://www.your-site.com/custom.

and You'll see following message.

My Custom Page

0

If you want it within the WordPress theme include the script in a Page Template within the theme folder your site is using. Then create a page and select that page template.

Alternatively you'll need to add a rule to the .htaccess to stop WordPress intercepting the script.

2
  • Turns out that WordPress by default would allow the custom PHP script to execute. The problem here was that the script was nested in several folders and it wasn't initially clear what the URL was to access it.
    – jbsound
    Aug 24, 2012 at 19:36
  • @jbsound can you be clear how did you fix it? thanks
    – Tinker
    Nov 15, 2017 at 21:13
0

Create a page template and insert your PHP code in there. For example:

<?php
/*
  Template Name: Your page name
 */

your php code
0

You can "override" WordPress using the Template Hierarchy mechanism.

  • Just create a new page in WordPress.
  • Find out its id (you can do it in the admin panel easily)
  • Create a PHP file in the template directory named page-IDOFYOURPAGE.php
  • Insert your code into the page you created

WordPress will take care of loading your code, executing the code in it using the WP URL structure.

0

@jbsound, I had the same problem.

Solved adding a die(); at the end of static php in order to prevent wordpress from change status header in Error 404.

// At the end of the page
die();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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