薇晓朵博客改版重启使用,需要严肃对待优质内容,所以把各方面的参数需要调整公布下,显示效果如下:
效果如下
function reading_time_shortcode( $atts ) {
$post_id = get_the_ID();
$post_content = get_post_field( 'post_content', $post_id );
$word_count = preg_match_all( '/[\p{L}\'\-]+|\p{Han}+/u', $post_content, $matches );
$reading_time = ceil( $word_count / 200 ); // Assumes an average reading speed of 200 words per minute
return '<p>预计阅读时间:'.$reading_time.'分钟</p>';
}
add_shortcode( 'reading-time', 'reading_time_shortcode' );
调用简码输入 [reading-time]