Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Make reading time support Ibrani language */
- add_action(
- 'init',
- function () {
- remove_action( 'jnews_render_after_meta_left', array( \JNews\Single\SinglePost::getInstance(), 'reading_time_meta' ), 10 );
- add_action( 'jnews_render_after_meta_left', 'new_reading_time_meta', 10 );
- }
- );
- function new_reading_time_meta() {
- if ( new_show_reading_time_meta() ) {
- $output = '';
- if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
- $wpm = (int) vp_metabox( 'jnews_single_post.override.0.post_reading_time_wpm' );
- } else {
- $wpm = (int) get_theme_mod( 'jnews_single_reading_time_wpm', 300 );
- }
- $content = get_post_field( 'post_content', get_the_ID() );
- if ( $content && $wpm ) {
- $content = strip_shortcodes( $content );
- $word_count = substr_count( $content, ' ' ) + 1;
- error_log( $word_count );
- $word_count = ceil( $word_count / $wpm );
- $reading_time = jnews_return_translation( 'Reading Time: ', 'jnews', 'reading_time' );
- if ( defined( 'JNEWS_FRONT_TRANSLATION' ) ) {
- $reading_time .= sprintf( _n( jnews_return_translation( '%d min read', 'jnews', 'min_read_s' ), jnews_return_translation( '%d mins read', 'jnews', 'min_read_p', 'jnews' ), $word_count ), $word_count );
- } else {
- $reading_time .= sprintf( _n( '%d min read', '%d mins read', $word_count, 'jnews' ), $word_count );
- }
- if ( $word_count ) {
- $output =
- '<div class="jeg_meta_reading_time">
- <span>
- ' . $reading_time . '
- </span>
- </div>';
- }
- }
- echo jnews_sanitize_by_pass( $output );
- }
- }
- function new_show_reading_time_meta() {
- if ( vp_metabox( 'jnews_single_post.override_template' ) ) {
- $flag = vp_metabox( 'jnews_single_post.override.0.show_post_reading_time' );
- } else {
- $flag = get_theme_mod( 'jnews_single_reading_time', false );
- }
- return apply_filters( 'jnews_single_show_reading_time', $flag, get_the_ID() );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement