-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeccas_plugin.php
More file actions
31 lines (25 loc) · 851 Bytes
/
beccas_plugin.php
File metadata and controls
31 lines (25 loc) · 851 Bytes
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
<?php
/*
Plugin Name: Becca's Plugin
Plugin URI: weekendofwordpress.wordpress.com
Description: This plugin adds a wordcount to each post
Version: 1.0
Author: rgraber
License: GPL
*/
function add_word_count($text)
{
# the_content includes the title, so need to subtract the wordcount
$num_words = str_word_count($text) - str_word_count(get_the_title());
$html_wrapper = sprintf("<div class='word_count'>This post has %d words</div>", $num_words);
$text = $text . $html_wrapper;
return $text;
}
function add_word_count_stylesheet() {
// Respects SSL, Style.css is relative to the current file
wp_register_style( 'prefix-style', plugins_url('word_count.css', __FILE__) );
wp_enqueue_style( 'prefix-style' );
}
add_filter('the_content', 'add_word_count');
add_action( 'wp_enqueue_scripts', 'add_word_count_stylesheet' );
?>