如何计算文章阅读时间

function get_post_reading_time($post_id = null) {
    if (!$post_id) {
        global $post;
        $post_id = $post->ID;
    }
    
    $content = get_post_field('post_content', $post_id);
    $content = strip_shortcodes($content);
    $content = strip_tags($content);
    
    $word_count = str_word_count($content);
    $reading_time = max(1, ceil($word_count / 200));
    
    return $reading_time;
}

// Shortcode version (optional)
function reading_time_shortcode($atts) {
    return get_post_reading_time() . ' min read';
}
add_shortcode('reading_time', 'reading_time_shortcode');
×
如何计算文章阅读时间

如何计算文章阅读时间

function get_post_re...