Created
March 24, 2022 03:44
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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