1

I created a bookshop website and got header function, footer function and login menu on my front page.

All functions are declared in functions.php and connected to hooks.

My front page runs correctly.

But I try to call registration menu file from one of my options of login menu (file page-non-member.php) and to use use header from front page as a header on this page.

I try to use this:

require( dirname( __FILE__ ) . '../wp-load.php' );
if ( function_exists( 'get_template_part' ) ) {
    echo "get_template_part found";
}
get_template_part( 'mybookshop', 'header' );  

or that:

do_action( 'create_header_html', 'Make registration' );

But in both cases, I got the next message

Warning: require(W:\domains\wpfolder\wp-content\themes\mybookshop../wp- load.php): failed to open stream: No such file or directory in W:\domains\wpfolder\wp-content\themes\mybookshop\page-not-member.php on line 4

Fatal error: require(): Failed opening required 'W:\domains\wpfolder\wp- content\themes\mybookshop../wp-load.php' (include_path='.;w:/modules/php/PHP-5.6;w:/modules/php/PHP-5.6/PEAR/pear') in W:\domains\wpfolder\wp-content\themes\mybookshop\page-not-member.php on line 4".

Structure of my folders:
-- WordPress root directory
 |-- file wp-load.php
 |
 ....
 |
 -- my site(bookshop) root directory
 |-- header.php,header.php, page-home-page.php, page-not-member.php, etc
 |
  ....

I use a local server(OpenServer). What is the problem and how can I resolve it?

0

1 Answer 1

2

First of all, don't do that. Including WordPress's engine in some external PHP file is not recommended at all. It has more downsides than upsides.

If you want to access WordPress's functions, create your PHP file inside the theme's folder, or create a plugin. You can even create an AJAX request if you really need to access some data directly by a URL.

Now, about your error. It seems like you are trying to include wp-load.php from one of your theme's files. If it is so, then that's not necessary. Theme's files already have access to WordPress's functions. Just remove the require... and you will be fine.

Let's say for some unknown reasons they don't, and you HAVE to include wp-load.php. This file exists in the root folder of your installation, and you have to go back 3 times to include it. So it will look like this:

../../../wp-load.php

Once again, please don't do this. It's not a good practice.

4
  • Thank you for reply. I DID NOT put wp-load.php in my site root directory. It is placed in WordPress root directory as WP installed. I added to my question structure of my folders. But from uknown reasons WP search this file in my site root directory, when i call WP standart functions (get_template_directory_uri(),get_template_part(),` do_action(), etc...) from file page-non-member.php. If i call them from standart WP files: header.php, footer.php, 'page-home-page.php (front page slug renamed from page.php) everything is working perfectly. And this is a problem....
    – adrian
    Jun 30, 2017 at 9:22
  • @adrian By site root I meant the entire site's root, which would be WordPress's installation directory. I still don't understand how you are doing this. If you are using functions inside the template files, they should work. Remember, you can not access your template files directly! They won't run that way!
    – Johansson
    Jun 30, 2017 at 13:14
  • I have installed WP locally on my PC. I use OpenServer to emulate internet. OS is configurated to recognize site root for WordPress as ...\wpfolder\.. folder (like localhost). I placed all files of WordPress in this folder (as OS recomended). Total path is: wpfolder\wp-content\ themes\bookshop`(my site folder).,You can see structure in my question post. If i am using functions inside template files (header.php` etc.) - everything is correct. But problem is: can i use functions inside of custom page-not-member.php which is not template file. That is what is everything is about!
    – adrian
    Jun 30, 2017 at 18:40
  • @adrian In that case, no you can't. They must be a part of template and run with WordPress. If you want to have your own separate php file, you need to create a plugin instead.
    – Johansson
    Jun 30, 2017 at 18:47

Your Answer

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

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