Created
July 14, 2018 14:38
-
-
Save hugodias/6622556ace1443d3927bde8282b50e36 to your computer and use it in GitHub Desktop.
Wordpress Reading time function with I18n Support
This file contains hidden or 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 | |
if ( ! function_exists( 'reading_time' ) ): | |
/** | |
* Display post reading time in minutes | |
* | |
* @param $post_content | |
* | |
* @return string | |
*/ | |
function reading_time( $post_content ) { | |
$word_count = str_word_count( strip_tags( $post_content ) ); | |
$readingtime = ceil( $word_count / 200 ); | |
$est = sprintf( // WPCS: XSS OK. | |
esc_html( _nx( | |
'1 minute to read', | |
'%1$s minutes to read', | |
$readingtime, | |
'minutes to read', | |
'my_domain' | |
) ), | |
number_format_i18n( $readingtime ) | |
); | |
return $est; | |
} | |
endif; |
This file contains hidden or 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
#: ../inc/extras:107 | |
#, php-format | |
msgctxt "minutes to read" | |
msgid "1 minute to read" | |
msgid_plural "%1$s minutes to read" | |
msgstr[0] "1 minuto para ler" | |
msgstr[1] "%1$s minutos para ler" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment