Header Ads

Header ADS

Wordpress simple word count plugin

 Wordpress simple word count plugin

<?php

/**

 * 

 */

/*

Plugin Name: Word Count

Plugin URI: https://developerzakir.blogspot.com/

Description: Word count from wordpress post.

Author: Zakir BD

Author URI: https://developerzakir.blogspot.com/

License: GPLv2 or later

Version: 1.0

Text Domain: word-count

Domain Path: /languages/


*/




function wordcount_load_textdomain(){

load_plugin_textdomain('word-count', false, dirname(__FILE__). "/languages");


}

add_action("plugins_loaded", "wordcount_load_textdomain");




function wordcount_countword($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_countword');



//use for reading time count


function wordcount_reading_time($content){

$stripped_content = strip_tags($content);

$wordn = str_word_count($stripped_content);


$reading_minutes= floor($wordn/200);

$reading_second = 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_minutes, $reading_second,  $wordn, $tag);



}


return $content;


}

add_filter("the_content", 'wordcount_reading_time');


No comments

Theme images by fpm. Powered by Blogger.