How to use __() and _e() functions in other PHP files?

Hi,

I would like to add those functions, for translation purpose, to the shortcode generator file which is in sub-folder of theme directory. It’s a general PHP file so once I added, the following error showed up:

Fatal error: Call to undefined function _e() in [file path].

Could you please advise how to achieve that?

Thanks in advance!

Paul

You have to load WordPress

if ( !defined('ABSPATH') ) {
	/** Load WordPress Bootstrap */
	require_once('../../../wp-load.php');
}

You may have to change the path

That perfectly works! Thank you @revaxarts. :slight_smile: