I was using the following: get_home_path();
in my functions.php as referenced in the docs – but I get the error:
Call to undefined function get_home_path() in ...
I'd like to include a file using it. I noticed there is also the constant ABSPATH
. Is there any reason I shouldn't just use ABSPATH
as an alternative to get_home_path()
?
Edit
I am using it as so (this is crazy simple) – in my functions.php file at the start of the file I have put:
require_once( ABSPATH . 'vendor/autoload.php' );
If I put:
$path = get_home_path();
require_once( $path . 'vendor/autoload.php' );
That's when it all goes wrong, with the generic error about the function not being available.
I was using the following: get_home_path();
in my functions.php as referenced in the docs – but I get the error:
Call to undefined function get_home_path() in ...
I'd like to include a file using it. I noticed there is also the constant ABSPATH
. Is there any reason I shouldn't just use ABSPATH
as an alternative to get_home_path()
?
Edit
I am using it as so (this is crazy simple) – in my functions.php file at the start of the file I have put:
require_once( ABSPATH . 'vendor/autoload.php' );
If I put:
$path = get_home_path();
require_once( $path . 'vendor/autoload.php' );
That's when it all goes wrong, with the generic error about the function not being available.
Share Improve this question edited Jun 15, 2020 at 8:21 CommunityBot 1 asked Sep 23, 2015 at 10:14 DjaveDjave 2584 silver badges25 bronze badges 3 |2 Answers
Reset to default 1get_home_path()
only works when WP admin scripts are loaded.
ABSPATH
is defined in wp-config.php so works anytime after the config file is loaded, so it should be totally fine for your use.
It is set to the dirname(__FILE__) + trailing slash
of wp-load.php (same location as e.g. wp-config.php). dirname
here returns the absolute path where WordPress is installed. For example, /home/user/public_html
and ABSPATH
adds a trailing slash
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
// So,
ABSPATH == '/home/user/public_html/'; // WP files are in public_html
So if you have a folder structure such as this:
- public_html/
- - wp-admin/
- - wp-content/
- - wp-includes/
- - wp-config.php
- - wp-load.php
- - vendor/
- - - autoload.php
- ...
You can put the following in your theme's functions.php file to load the autoload.php file
require_once( ABSPATH . 'vendor/autoload.php' );
Perhaps this issue is that get_home_path()
can only be used in the admin?
As it says in small letters in the docs:
This is a backend function.
ABSPATH
is used byget_home_path()
if you look at the source code – Pieter Goosen Commented Sep 23, 2015 at 10:32wp-content/themes/your-theme
– TheDeadMedic Commented Sep 23, 2015 at 13:55