Title: require_once __DIR__
Last modified: June 5, 2023

---

# require_once __DIR__

 *  Resolved [Giorgos](https://wordpress.org/support/users/pxlsse/)
 * (@pxlsse)
 * [3 years ago](https://wordpress.org/support/topic/require_once-__dir__/)
 * I have an issue with require a file in a directory. E.g I want to require a file
   in the directory /vendor/autoload.php
 *     ```wp-block-code
       require_once __DIR__ . '/vendor/autoload.php';
       use ipinfo\ipinfo\IPinfo;
       $access_token = '3278463abc';
       $settings = ['cache_disabled' => true];
       $client = new IPinfo($access_token);
       $ip_address = '000.000.00.00.0';
       $details = $client->getDetails($ip_address);
   
       $details->loc;
       ```
   
 * I get the error:
   `Failed opening required /home2/malesbarbercom/public_html/wp-
   content/plugins/insert-headers-and-footers/includes/vendor/autoload.php (include_path
   =.:/opt/alt/php81/usr/share/pear:/opt/alt/php81/usr/share/php:/usr/share/pear:/
   usr/share/php)`
 * Why does it add “`/wp-content/plugins/insert-headers-and-footers/includes/`” 
   in the directory output? And what is the solution?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * (@gripgrip)
 * [3 years ago](https://wordpress.org/support/topic/require_once-__dir__/#post-16795546)
 * Hi [@pxlsse](https://wordpress.org/support/users/pxlsse/),
 * That’s happening because you are trying to use a relative path and the script
   is looking for the vendor/autoload.php file in the directory of where the snippet
   is being executed, which is inside the WPCode plugin.
 * You need to use an absolute path if you uploaded the vendor folder to your website.
   Are you using composer and uploaded a vendor folder to your website? If not, 
   that will not work.
 *  Thread Starter [Giorgos](https://wordpress.org/support/users/pxlsse/)
 * (@pxlsse)
 * [3 years ago](https://wordpress.org/support/topic/require_once-__dir__/#post-16795974)
 * Hi Mircea and thanks for a fast reply!
   I installed the package through cpanel
   PHP Pear.I tried to change the path in the code to the full ‘absolute’ path (
   which is: home2/*domain*/public_html/vendor/autoload.php), but same issue…
 *  Plugin Author [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * (@gripgrip)
 * [3 years ago](https://wordpress.org/support/topic/require_once-__dir__/#post-16796586)
 * Hi [@pxlsse](https://wordpress.org/support/users/pxlsse/),
 * That’s likely not the absolute path, you can try using the ABSPATH constant but
   in either case you should first check via FTP that the file you are trying to
   include is actually available in the public_html folder.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘require_once __DIR__’ is closed to new replies.

 * ![](https://ps.w.org/insert-headers-and-footers/assets/icon-256x256.png?rev=2758516)
 * [WPCode - Insert Headers and Footers + Custom Code Snippets - WordPress Code Manager](https://wordpress.org/plugins/insert-headers-and-footers/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/insert-headers-and-footers/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/insert-headers-and-footers/)
 * [Active Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/insert-headers-and-footers/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * Last activity: [3 years ago](https://wordpress.org/support/topic/require_once-__dir__/#post-16796586)
 * Status: resolved