What does the WordPress "_e()" function do?
You've stumbled upon a common source of confusion in legacy WordPress themes: the _e() function. It appears frequently, often cluttering the codebase without obvious side effects if removed. When you strip these calls out, the theme renders normally, yet many developers hesitate to touch them due to uncertainty about their purpose or fear of breaking functionality. If your primary goal is site optimization and faster load times, understanding exactly what _e() doesâand whether it can be safely deletedâis essential before you proceed with aggressive code cleanup.
Technically, _e() stands for "echo the translation." It is a wrapper around WordPress's standard __() function. While __() simply returns a translated string without outputting it to the browser, _e() immediately echoes that string. The core logic resides in the fact that it checks if a translation exists for a specific text domain and language before falling back to the default string provided as an argument.
Here is how you typically encounter it:
_e( 'Welcome to our site', 'my-theme' );
In this snippet, WordPress looks for a translation of "Welcome to our site" within the my-theme text domain. If a translation file (usually .pot or .po) defines a string for that key in the current user's language settings, _e() outputs the localized version. If no translation is found, it outputs the original English string.
The critical distinction between using _e() and standard echo combined with _() lies in maintainability and localization workflows. When you use _e(), you are explicitly stating that this text is intended to be translatable. By wrapping your static strings in this function, you signal to translation management systems (like Crowdin or Transifex) that these specific keys need human review before being pushed to production locales.
However, if your theme does not support multi-language functionality and you are targeting a single language (e.g., English only), the _e() function becomes redundant. In a monolingual environment, __() returns the same string as _e(), and neither provides any performance benefit over direct echo statements. The overhead introduced by _e() is negligible for modern servers but accumulates when used excessively across hundreds of template files.
Is it safe to remove?
Yes, but with a caveat regarding your translation strategy. If you are optimizing a static English-only site, removing all instances of _e() and replacing them with direct echo statements or esc_html() (if the output is unescaped text) will not break the theme's functionality. The visual output remains identical because there are no other translations to load.
However, if you intend to add multi-language support later, deleting these functions removes the hooks required for translation management tools to work. You would have to manually refactor your codebase to use __() everywhere and wrap your echo calls separately to regain that capability.
Performance implications
Regarding site speed: the impact of _e() on load times is minimal but non-zero. Every call involves a function lookup, a check against the translation loader, and a string comparison. While this adds fractions of a millisecond per call, removing thousands of instances from a bloated theme can yield a measurable improvement in Time to First Byte (TTFB) and overall payload size.
The real performance win comes not just from removing _e(), but from what often accompanies it: unused translation files. If your theme loads my-theme.pot or large .mo files that contain thousands of keys, only a fraction of which are actually used, you are paying the cost of parsing and loading unnecessary data.
To optimize effectively:
- Audit usage: Use a search tool to find every instance of
_e()in your theme. - Check dependencies: Ensure none of these calls rely on dynamic arguments passed from plugins that expect the function to exist (rare, but possible).
- Consolidate: Replace
_e('text', 'domain')withecho esc_html__('text', 'domain');if you want to keep translation support without the immediate echo, then remove the domain argument entirely if localization is not needed:echo esc_html('text');.
If you are building a high-performance theme or migrating an old one, stripping out _e() in favor of direct output (with proper escaping) is a valid optimization strategy. It simplifies the codebase, reduces the dependency on the translation system for static text, and eliminates the overhead of loading unused locale data. Just remember that if you ever decide to go international, you'll need to refactor those echo statements back into __() wrappers to restore the localization workflow.