Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress WordPress Theme Development Building Out WordPress Navigation The wp_nav_menu Function

Why this _() function was used instead of just entering the string?

Taking this code as example:

function register_theme_menus() {
  register_nav_menus(
    array(
      'primary-menu' => _('Primary Menu')
    )
  );
}

Why use _() instead of just entering the string? According to the Wordpress Codex all it do is take a string and return it back.

function _($string) {
    return $string;
}

1 Answer

Malte Zwillus
Malte Zwillus
9,448 Points

Hey Fabrício,

this is for making strings translatable. Every string that is inside of a translation function ( e.g. __(), _x() ... ) can be translated through a translation file. You can find more information here: https://codex.wordpress.org/I18n_for_WordPress_Developers

Regards Malte

Thank you.