Saladin Akara
Saladin Akara

Reputation: 2548

How to include PHP file in Wordpress that is outside the Wordpress Environment

I am using a custom CMS for a website that deals with 90% of the site's pages and content.

However, for the news/blog section of the site, I am using Wordpress.

I'm able to include the necessary Wordpress files to pull in posts to the main site, but cannot do the reverse.

I want to be able to call a php file into the header of Wordpress so I have access to the CMS's classes, primarily for navigation.

I've tried a search but can't seem to find an answer.

Additional Information:

Clarification:

I don't want to create a custom template or include Wordpress functionality outside of Wordpress. I want to pull external classes from a CMS, which is a level above Wordpress, into Wordpress so that I can use it throughout the Wordpress installation.

Upvotes: 1

Views: 4930

Answers (4)

samjco-com
samjco-com

Reputation: 409

Perhaps this?

include(dirname(__FILE__) . '/includes/somefile.php');
//include_once

OR

$rootpath = $_SERVER['DOCUMENT_ROOT'];
$rootpath .= "/includes/somefile.php";
include_once($rootpath);

Upvotes: -1

Saladin Akara
Saladin Akara

Reputation: 2548

I managed to fix this by altering the include line to reference the folder above the Wordpress root.

So, the line became require_once "../path/to/file" instead of just require_once "/path/to/file"

Upvotes: 0

kaleem
kaleem

Reputation: 570

Method 1 :

<?php
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
?>

Method 2 :

<?php
define('WP_USE_THEMES', false);
require('./wp-load.php');
?>

Upvotes: 1

Yatin Khullar
Yatin Khullar

Reputation: 1590

You should go with custom page template.

Its an easy way to include php file in wordpress because in thisway you can easily include wordpress theme header and footer.

To create a custom page template.

You have to simply create new .php page and at start of page just include this code.

<?php
/*
Template Name: My custom page template name
*/
?>
// your code 

To read in detail about Wordpress custom page template click here

I hope it will help you.

Upvotes: 2

Related Questions