0

I wrote my own PHP file and include it to Wordpress using: http://www.paulund.co.uk/rewrite-urls-wordpress

But now if i try in this file use Wordpress variable or function (for example get_header();) i see only blank screen. I understand that this file can not use these variables but how can i link this file with Wordpress?

I think it is simple and i tried to find answer but i don't know how to name that. Can you please help me?

I see this error reason: Fatal error: Call to undefined function get_header() in /home1/colleie6/public_html/wp-content/themes/flatads/filter.php on line 9

fliprs
  • 47
  • 1
  • 6
  • 1
    Put `error_reporting(E_ALL); ini_set('display_errors', 1);` at the top of your PHP file, refresh page, tell us the errors that it shows – Alex Jul 21 '14 at 16:11
  • I added that to main question - thank you. – fliprs Jul 21 '14 at 16:15
  • How is this file being loaded? What is the URL that you access it with? `filter.php` is not a file that gets loaded by default logic, how/where is that being included? – Steve Buzonas Jul 21 '14 at 16:21

2 Answers2

0

One way to access WordPress native functions in external PHP file is including 'wp-blog-header.php' file into your external PHP file:

e.g. require_once('wp-blog-header.php'); //make sure to change the path according to your external file location
Domain
  • 11,562
  • 3
  • 23
  • 44
  • If you are requiring `wp-blog-header.php`, which is what `index.php` does to bootstrap wordpress, you should `define('WP_USE_THEMES', false);`. – Steve Buzonas Jul 21 '14 at 16:25
-1

Try including wp-load.php, as outlined on this answer (as per the comments, you don't need the other files).

EDIT

As per the comment from Steve Buzonas, this answer's wrong for your particular situation. I missed the mention of the tutorial, and thought you had a standalone page (much like the other question I linked to). Sadly, since it's the accepted answer, I can't delete it.

Looking at the tutorial, it looks like the code should be added to your theme's functions.php (though I'm tempting fate by not testing it).

Community
  • 1
  • 1
Hobo
  • 7,536
  • 5
  • 40
  • 50
  • The tutorial linked discusses hooking in to wordpress to add functionality, the path of the file is a theme file and should already have wordpress loaded. Including `wp-load.php` is generally a bad way to do things unless you have significantly custom logic, such as an entirely separate code base that has some interaction with wordpress. – Steve Buzonas Jul 21 '14 at 16:24
  • Fair point - I missed the mention of the tutorial. You're right - I've suggested probably the worst possible way to do this. I had thought it was a standalone PHP file. Looks like the code it mentions should be in the theme's `functions.php`. – Hobo Jul 21 '14 at 18:37