__( "Reading Time", 'betterdocs' ), 'the_content' => get_the_content() ]; } public function render( $atts, $content = null ) { $this->views( 'shortcodes/reading-time' ); } public function view_params() { $single_doc_content = $this->attributes['the_content']; $content_without_html_tags = strip_tags( $single_doc_content ); preg_match_all('/<[^>]*>|[\p{L}\p{M}]+/u', $content_without_html_tags, $matches ); $reading_total_words = ! empty( $matches[0] ) ? count( $matches[0] ) : count( [] ); //lets assume an adult reads 200 words per minute, based on this information calculate the reading time $minutes = floor( $reading_total_words / 200 ); $seconds = floor( $reading_total_words % 200 / ( 200 / 60 ) ); $calculate_time = $minutes . ' ' . __( 'min', 'betterdocs' ) . ' ' . ( $seconds != 0 ? $seconds . ' ' . __( 'seconds', 'betterdocs' ) . ' ' . __( 'read', 'betterdocs' ) : __( 'read', 'betterdocs' ) ); return [ 'time' => $calculate_time ]; } }