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


#1

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


#2

You have to load WordPress

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

You may have to change the path


#3

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