DEV Community

TechzPad
TechzPad

Posted on

How to Create Total Word Count Tools in WordPress

A total word count tools in WordPress is essentially a feature that allows users to determine the number of words in a specific piece of content. This tool is especially beneficial for bloggers, writers, and editors who aim to maintain a certain word count range for their posts. Accurate word count helps in optimizing content for SEO, ensuring consistency in writing style, and creating content that meets the desired length criteria.

  1. Create a New Page:

Create a new page from your WordPress dashboard. Name it “tpad_wordcoount.php” or any other title of your choice.
`<?php
/*
Template Name: TechzPad WC Tools
*/

get_header();
?>
//Your Code Here

<?php get_footer(); ?>`

  1. Add HTML for the Word Count Tool: <div class="techzpad-word-count"> <div class="container"> <form id="word-count-form"> <textarea id="content" rows="5" placeholder="Enter your text here..."></textarea> <button id="count-button">Count Words</button> </form> <div id="word-count-result"></div> </div> </div>
  2. Add CSS for the Word Count Tool:

.techzpad-word-count {
text-align: center;
}
#word-count-form {
margin: 20px 0;
}
#content {
width: 100%;
}
#count-button {
background-color: #0073e6;
color: #fff;
border: none;
padding: 10px 20px;
cursor: pointer;
transition: background-color 0.3s;
}
#count-button:hover {
background-color: #005bbf;
}
#word-count-result {
margin-top: 10px;
font-weight: bold;
}

  1. Add JavaScript for the Word Count Tool:

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
jQuery(document).ready(function($) {
$("#count-button").click(function(e) {
e.preventDefault();
var content = $("#content").val();
var words = content.split(/\s+/).filter(Boolean).length;
$("#word-count-result").text("Total Word Count: " + words);
});
});
</script>

Combine all code in one page and save it. If you want to see demo click here

Top comments (0)