How to specify the path for require_once in a child theme?

I have a child theme folder called themes/child-theme and inside I have a file dashboard_payments.php.
Under the child theme folder I’m creating a new folder called gateway and inside there’s a config.php.

So, how do I do a require_once inside dashboard_payments.php to call the file gateway/config.php? How would the require_once or include line look like?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Since 4.7 get_theme_file_path() is the right function to use:

require_once get_theme_file_path( 'gateway/config.php' );

Method 2

You can use either

require_once(get_stylesheet_directory() . '/gateway/config.php');

or (should be faster)

require_once(__DIR__ . '/gateway/config.php');


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x