Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
201805 WCEU Code samples
<?php
/*
* Example of translators comment for a text string with a single placeholder.
*/
/* translators: %s: the version number of a WordPress release. */
esc_html_e( 'Wordpress %s is awesome!' );
/*
* Example of translators comment for a text string with multiple numbered placeholders.
*/
/* translators: 1: the version number of the current WordPress release; 2: the version number which will come after that. */
esc_html_e( 'Wordpress %1$s is awesome! and %2$s will be even better' );
/*
* Example of INCORRECTLY placed translators comment.
*/
/* translators: %s is the version number of a WordPress release. */
echo '<h2>' . sprintf(
esc_html__( 'Some translatable text with %s placeholder' ), $replacement
);
/*
* Example of CORRECTLY placed translators comment.
*/
echo '<h2>' . sprintf(
/* translators: %s is the version number of a WordPress release. */
esc_html__( 'Some translatable text with %s placeholder' ),
$replacement
);
/*
* Examples of CORRECTLY placed translators comment and code layout when dealing with embedded PHP.
*/
<?php /* translators: %s is the version number of a WordPress release. */ ?>
<h2> <?php printf( esc_html__( 'Some translatable text with %s placeholder' ), $replacement ); ?></h2>
<!-- Alternative code layouts: -->
<?php
/* translators: %s is the version number of a WordPress release. */
$text = sprintf( __( 'Some translatable text with %s placeholder' ), $replacement );
?>
<h2> <?php echo esc_html( $text ); ?></h2>
<h2>
<?php
printf(
/* translators: %s is the version number of a WordPress release. */
esc_html__( 'Some translatable text with %s placeholder' ),
$replacement
);
?>
</h2>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment