How to Display Post Words Count

I don’t know why some people like to display post words count on their blog, but I personally don’t like this function. In case you are the ones like this function, then you can copy and paste the following coding to functions.php.

function wcount(){
ob_start();
the_content();
$content = ob_get_clean();
return sizeof(explode(" ", $content));
}

And then you can call the function to get the number of words of the current post:

<?php echo wcount(); ?>

Thanks to Digging Into WordPress for this excellent code.

How to Display Most Popular Posts Without a WordPress Plugin

Many blogs have display most popular posts on their blog to make visitors stay longer on their posts, this is one of the way to attract more visitors to your blog. We actually can install a wordpress popular posts plugin to display our most popular posts, but if you don’t want to use plugin, you can simply hack your wordpress theme to do it manually.

Copy and paste the following code to the sidebar.php file, if you want to change the number of displayed posts, simply change the “5″ to your desired number.

<h2>Popular Posts</h2>
<ul>
<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");
foreach ($result as $post) {
setup_postdata($post);
$postid = $post->ID;
$title = $post->post_title;
$commentcount = $post->comment_count;
if ($commentcount != 0) { ?>
<li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>">
<?php echo $title ?></a> {<?php echo $commentcount ?>}</li>
<?php } } ?>
</ul>

Please note that the 5 most popular posts displayed is basing on the 5 most commented posts .

How to Prevent Images on Posts from Being Too Large

Everyone will put images on the posts, sometimes the images displayed on the posts looks too large and may be break your current theme layout, it isn’t nice. There is a solution to avoid this problem with the help of adding the following code to your style.css file.

What you need to do is open style.css file, and simply copy and paste the following code to this file.

.post img {
max-width: 540px; /* Adjust this value according to your content area size*/
height: auto;
}

Most wordpress themes display posts content within a tag. In case this doesn’t work, you can try another way as below.

.maxwidth img {
max-width: 540px; /* Adjust this value according to your content area size*/
height: auto;
}

Use class=”maxwidth” on your IMG element. For example,

<img src="”../images/abc.jpg”" class="maxwidth" />

How to Disable WordPress AutoSave Function

Everyone should know wordpress has AutoSave function, some people really don’t like it, including me because it doesn’t help me too much. To disable AutoSave function of wordpress, simply copy and paste the following code to the function.php file. In case you want to enable again, you can just delete the code.

function disableAutoSave() {
wp_deregister_script('autosave');
}
add_action('wp_print_scripts', 'disableAutoSave');