by Noura Yehia


WordPress is becoming so powerful that you can use it to do whatever comes in your mind. User love it for its flexibility, you have plugins to enhance its power and you can hack your theme code to add unique functionality.
In this article, we’ll show you 10 new powerful WordPress hacks, tricks and plug-ins with a good explanation, so you understand how it works and modify it to your needs.

1. Post Image Feature (the_post_thumbnail)

the_post_thumbnail is one of my favorite additions to WordPress 2.9, a new thumbnail feature for themes where you will be able to easily upload a post thumbnail. Justin Tadlock wrote an interesting tutorial explaining various things you need to know about WordPress 2.9’s post image feature.

To add support for the post image feature in a theme, You only need one line of code to turn this feature in your theme. Add this to your theme’s functions.php file:

add_theme_support( 'post-thumbnails' );

After that, you’ll need to call the image somewhere within The Loop in your template files. You’d do this by adding this line of code:

<?php the_post_thumbnail( 'medium' ); ?>

The previous code calls for medium-sized images in your template files. Fore more information about this feature, make sure you check Justin Tadlock’s tutorial and Michael Preuss guide.

2. WordPress Threaded Comments

One of the big enhancements of the WordPress Comment’s features is the threaded comment functionality. Many bloggers search for themes has this built-in functionality. However, won’t it be easier if we just use a plugin. Below you will find an amazing WordPress plugin that will just add this feature without the need to edit any code of your theme files.
WordPress Thread Comment:
This Plugin is an enhancement for WordPress’s comment function. It enables users to reply on a exist comment, and the discussion will be displayed threaded or nested.

3. Contactable – Contact Form Easy with WordPress

Frank Bültge shows how easy and resource friendly it is to integrate a jQuery contact form in WordPress.
He used for the example the great form Plugin Contactable for jQuery by Philip Beel. This Plugin is designed to make contact/feedback forms simpler and more accessible.

4. Exclude A Category From Turn Off Comments Automatically

If you would like to automatically turn off comments on everything after a certain period, all you have to do is go to your discussion settings, and set to automatically turn off comments on everything after x days. However, on certain things, you want the comments to be left on forever in a certain category. All you have to do is follow the hack we found in this post, just copy the code below into your functions.php and change the $cat values.

/**
 * Close comments on an old post.  Hooked to comments_open and pings_open.
 * small modifications on the default functions of WordPress
 *
 * @param bool $open Comments open or closed
 * @param int $post_id Post ID
 * @param int $cat Category ID (cat_ID), set '' or empty for all categories
 * @param int $days_old Days to close comments, set '' for use value from settings
 * @return bool $open
 */
function wpe_close_comments_for_old_post( $open, $post_id, $cat = array(1, 4), $days_old = '' ) {
	if ( !$open )
		return $open;
 
	if ( in_category($cat) )
		return $open;
 
	if ( '' === $days_old )
		$days_old = (int) get_option('close_comments_days_old');
 
	if ( !$days_old )
		return $open;
 
	$post = get_post($post_id);
 
	if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * 24 * 60 * 60 ) )
		return false;
 
	return $open;
}
add_filter( 'comments_open', 'wpe_close_comments_for_old_post', 10, 2 );
add_filter( 'pings_open',    'wpe_close_comments_for_old_post', 10, 2 );

Source : Exclude A Category From Turn Off Comments Automatically

5. How to disable HTML in WordPress comments

By default, WordPress allows certain tags in comments. Therefore commenters can add links, style text in bold and italics, add tables, and more. This can cause a lot of headache to you from spammers who can easily fill in your blog with comments linking to their websites. Fortunately there is a quick fix to this issue, whatever the commenter types will be displayed literally. No “certain tags are allowed” or “do this to code samples”. What this plugin does is it converts single quotes, double quotes, the less than symbol (<), the greater than symbol (>), and ampersands (&) to HTML entities whenever a comment is posted, so that they are displayed as-is when someone views the comment.

6. Create a Free Email Newsletter Service using WordPress

In this tutorial, we will learn the manual way to create a simple Email Newsletter Service for your WordPress blog by using WordPress and Feedburner with a few plugins to. You can track the performance of your newsletter by checking how many subscribers you have, how many clicks each link gets and much more.

Source : Create a Free Email Newsletter Service using WordPress

7. Alternate Post Styling On Your Home Page

While i was designing the current theme of Noupe.com, i wanted to display the first four posts bigger than the rest, with images and extended text, with the remaining posts shown more simply. Fortunately, Jean-Baptiste Jung sent me a smart solution where he created a custom loop that displays the first four posts different than the rest.

<?php
$postnum = 0;
while (have_posts()) : the_post(); ?>

<?php if ($postnum <= 4){ ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
  <div class="date"><span><?php the_time('M j') ?></span></div>
    <h2>(<?php echo $postnum;?>)<a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
	<div class="post-image" style="text-align:center;">
		<a href="<?php the_permalink() ?>"><img src="<?php bloginfo('template_directory' ); ?>/timthumb.php?src=<?php  echo catch_that_image(); ?>&amp;w=500&amp;h=200&amp;zc=1" alt="<?php the_title(); ?>" /></a>
	</div>
	<p><?php the_content('Read the rest of this entry &raquo;'); ?></p>
	<p class="more"><a href="#">Read More</a></p>
  </div>
</div>

<?php } else {
<div <?php post_class( 'single ' . $end ); ?> id="post-<?php the_ID(); ?>">
	<div class="post-content">
		<h3><a href="<?php the_permalink() ?>">(<?php echo $postnum; ?>)<?php the_title(); ?></a> <?php edit_post_link('_', '', ''); ?></h3>
		<p><?php the_excerpt( '' ); ?></p>
		<p class="more"><a href="#">Read More ?</a></p>
	</div>
</div><!-- End post -->

<?php }
	endwhile;
	?>

What he did was creating a PHP variable, named $postnum, which is invoked at the end of the loop. If $postnum is less than or equal to 4, the post is displayed in full. Otherwise, it is displayed in its more compact form.

Source : Alternate Post Styling On Your Home Page

8. Easy Retweet Button

John Resig created a simple script for tracking the number of people visiting a blog post from Twitter, in a completely unobtrusive manner. The script itself is completely standalone (no dependencies) and can be included in any page relatively painlessly. Additionally, since it’s just HTML, CSS, and JavaScript, it’s completely themeable and customizable to the style of your site.

To use it in your WordPress blog, you will just need to use the line of code below placed in your single.php theme file:

<a href="<?php the_permalink() ?>" class="retweet"><?php the_title(); ?></a>

9. Protect WordPress Against Malicious URL Requests

Many WordPress sites gets attacked with extremely malicious code, fortunately Jeff Starr wrote a simple script that
checks for excessively long request strings (i.e., greater than 255 characters), as well as the presence of either “eval(” or “base64” in the request URI.
How to use it:


To protect your site using this lightweight script, save the code as a plugin and activate in the WordPress Admin area. Once active, this plugin will silently and effectively close any connections for these sorts of injection-type attacks.

<?php 
/* 
Plugin Name: Block Bad Queries
Plugin URI: http://perishablepress.com/press/2009/12/22/protect-wordpress-against-malicious-url-requests/
Description: Protect WordPress Against Malicious URL Requests
Author URI: http://perishablepress.com/
Author: Perishable Press
Version: 1.0
*/
global $user_ID; if($user_ID) {
	if(!current_user_can('level_10')) {
		if (strlen($_SERVER['REQUEST_URI']) > 255 || 
			strpos($_SERVER['REQUEST_URI'], "eval(") || 
			strpos($_SERVER['REQUEST_URI'], "CONCAT") || 
			strpos($_SERVER['REQUEST_URI'], "UNION SELECT") || 
			strpos($_SERVER['REQUEST_URI'], "base64")) {
				@header("HTTP/1.1 414 Request-URI Too Long");
				@header("Status: 414 Request-URI Too Long");
				@header("Connection: Close");
				@exit;
		}
	}
} ?>

Source : Protect WordPress Against Malicious URL Requests

10. Curating Comments Threads: Feature Comments

Chris Coyier thought of a smart idea for a plugin. Two more buttons for comment moderation:feature and bury, handy to highlight comments that add value to your post. Utkarsh Kukreti created Feature/Bury Comments plugin for WordPress. This plugin lets the admin add “featured” or “buried” css class to selected comments.

<li id="comment-67793" class="comment even thread-even depth-1 buried">
</li>
<li id="comment-67794" class="comment odd alt thread-odd thread-alt depth-1 parent featured">

Literally all it does is giving you class names to work with. A simple Hook that you then use to apply unique styling to target with JavaScript to appropriately “feature” or “bury” them as you find necessary for your site.