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()?


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.

  • What is your exact usecase. I cannot really guess why you would get the error you are getting. Also, ABSPATH is used by get_home_path() if you look at the source code – Pieter Goosen Sep 23 '15 at 10:32
  • I'm using composer to install some dependencies of my Wordpress install. – Djave Sep 23 '15 at 12:18
  • Shouldn't you be working within your theme folder? So have composer & vendor set up inside wp-content/themes/your-theme – TheDeadMedic Sep 23 '15 at 13:55

get_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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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