• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Draft / The difference between __() and _x() in WordPress

The difference between __() and _x() in WordPress

Last updated on May 30, 2019 by Sal Ferrarello

Both __() and _x() are both WordPress translation functions. The function _x() does the same thing as the function __() except the _x() function accepts an additional parameter ($context).

The $context parameter allows you to have the same string translated in different ways. For example the string “tear” could be two different words:

  • a tear of sadness ran down my check
  • they tear off part of the ticket when I go to the ballgame

Using __() you can have only one translation for the string “tear” but by using _x() you can have different translations based on context.

echo _x( 'tear', 'noun: comes out of your eye when crying', 'fe_recipe' );
echo _x( 'tear', 'verb: to pull apart by force', 'fe_recipe' );
Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit
Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Draft, Programming Tagged With: WordPress

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in