Skip to content

Instantly share code, notes, and snippets.

@ericnicolaas
Created March 24, 2022 03:44
Show Gist options
  • Save ericnicolaas/e88c9cd3d05cc49c97b9fe499105195b to your computer and use it in GitHub Desktop.
Save ericnicolaas/e88c9cd3d05cc49c97b9fe499105195b to your computer and use it in GitHub Desktop.
Add a shortcode you can use to display different text based on the current locale.
<?php
/**
* This adds a new shortcode you can use to display different
* text based on the current locale.
*/
add_shortcode( 'if_locale', function( $atts, $content ) {
$defaults = array(
'language' => '',
);
$args = shortcode_atts( $defaults, $atts, 'if_locale' );
if ( empty( $args['language'] ) ) {
return do_shortcode( $content );
}
if ( $args['language'] === get_locale() ) {
return do_shortcode( $content );
}
return '';
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment