This repository has been archived on 2024-04-03. You can view files and clone it, but cannot push or open issues or pull requests.
kspace-wordpress-theme/functions/reading-time.php

38 lines
792 B
PHP
Raw Permalink Normal View History

2023-05-20 11:36:03 +02:00
<?php
/////////////////////////////////////////////////////////////////////////////
// Reading time
// Return the average reading time of an article
//
// Version 0.1
function reading_time() {
$content = get_post_field( 'post_content', $post->ID );
$word_count = str_word_count( strip_tags( $content ) );
$readingtime = ceil($word_count / 200);
if ($readingtime == 1) {
$timer = " minute";
} else {
$timer = " minutes";
}
$totalreadingtime = $readingtime . $timer;
return $totalreadingtime;
}
2023-05-20 14:48:22 +02:00
function image_number() {
$content = get_post_field( 'post_content', $post->ID );
$count = substr_count( $content, '<img' );
if ($count == 1) {
$timer = " image";
} else {
$timer = " images";
}
$imagenumber = $count . $timer;
return $imagenumber;
}
2023-05-20 11:36:03 +02:00
?>