-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathword-count.php
More file actions
61 lines (45 loc) · 1.99 KB
/
word-count.php
File metadata and controls
61 lines (45 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/*
Plugin Name: Page Word Count
Plugin URI: https://wordpress.com
Description: Count Words from any WordPress Post
Version: 1.0
Author: NF
Author URI: https://nf.me
License: GPLv2 or later
Text Domain: page-word-count
Domain Path: /languages/
*/
/*function wordcount_activation_hook(){}
register_activation_hook(__FILE__,"wordcount_activation_hook");
function wordcount_deactivation_hook(){}
register_deactivation_hook(__FILE__,"wordcount_deactivation_hook");*/
function wordcount_load_textdomain() {
load_plugin_textdomain( 'word-count', false, dirname( __FILE__ ) . "/languages" );
}
add_action( "plugins_loaded", 'wordcount_load_textdomain' );
function wordcount_count_words( $content ) {
$stripped_content = strip_tags( $content );
$wordn = str_word_count( $stripped_content );
$label = __( 'Total Number of Words', 'word-count' );
$label = apply_filters( "wordcount_heading", $label );
$tag = apply_filters( 'wordcount_tag', 'h2' );
$content .= sprintf( '<%s>%s: %s</%s>', $tag, $label, $wordn, $tag );
return $content;
}
add_filter( 'the_content', 'wordcount_count_words' );
function wordcount_reading_time( $content ) {
$stripped_content = strip_tags( $content );
$wordn = str_word_count( $stripped_content );
$reading_minute = floor( $wordn / 200 );
$reading_seconds = floor( $wordn % 200 / ( 200 / 60 ) );
$is_visible = apply_filters( 'wordcount_display_readingtime', 1 );
if ( $is_visible ) {
$label = __( 'Total Reading Time', 'word-count' );
$label = apply_filters( "wordcount_readingtime_heading", $label );
$tag = apply_filters( 'wordcount_readingtime_tag', 'h4' );
$content .= sprintf( '<%s>%s: %s minutes %s seconds</%s>', $tag, $label, $reading_minute, $reading_seconds, $tag );
}
return $content;
}
add_filter( 'the_content', 'wordcount_reading_time' );