How to Avoid Duplicated Comments Submitted

This is one way to combat spam comments if you can avoid duplicated comments are submitted on your posts, you can do some code modification as below in comments.php file. Why people post double comments because sometimes they are not aware that their comment is under moderation mode. Anyway, if you found your theme don’t have this option, then you can open comments.php and do some code modification.

1. Open comments.php and find the following code.

<p>
<input name="submit" type="submit" tabindex="5" value="<?php _e("Say it!"); ?>" />
</p>

2. Replace with

<p>
<blockquote>
Comment moderation is in use. Please do not submit your comment twice — it will appear shortly.
</blockquote>
<input name="submit" type="submit" tabindex="5" value="<?php _e("Say it!"); ?>" />
</p>

How to Make Your Title Tag SEO Friendly

Wordpress title tag also plays important role in SEO, it telling the search engine spider what your site covered, and allows your site to be indexed based upon the correct and most relevant keywords. If your site has good seo, then you will have lots of organic traffic from various search engines. So how to make your wordpress title tag SEO friendly?

Open header.php file, find the <title> tag, and replace it by the following code.

<title>
<?php if (is_home () ) {
bloginfo('name');
} elseif ( is_category() ) {
single_cat_title(); echo ‘ – ‘ ; bloginfo('name');
} elseif (is_single() ) {
single_post_title();
} elseif (is_page() ) {
bloginfo(’name’); echo ': '; single_post_title();
} else {
wp_title("",true);
} ?>
</title>

This code will generate title tags according to the following model:

  • Blog homepage -> display blog name.
  • Category page -> display the category name and the blog name.
  • Article page -> display the article title.
  • Static page -> display the blog name, and the page title.

How to Display Random Posts on Your Sidebar

Many readers seldom browse through our old post to read them out, but installing wordpress plugin like Pagenavi and Related Posts can help to give a new life for your old posts. There is another way to make your old posts have a good chance to read by reader, that is to display random posts on your sidebar.

To display random posts on your sidebar, simply copy and paste the following code to your sidebar.php.

<?php
query_posts(array('orderby' => 'rand', 'showposts' => 1));
if (have_posts()) :
while (have_posts()) : the_post();
the_title();
the_excerpt();
endwhile;
endif; ?>

How to Display Most Recent Twitter Tweets in WordPress Blog

Since Twitter became popular, many bloggers like to display recent twitter tweets on their website or blog. To display most recent twitter tweets, simply copy and paste the following code to your sidebar.php file.

<?php
// Your twitter username.
$username = "TwitterUsername";
// Prefix - some text you want displayed before your latest tweet.
// (HTML is OK, but be sure to escape quotes with backslashes: for example href=\"link.html\")
$prefix = "";
// Suffix - some text you want display after your latest tweet. (Same rules as the prefix.)
$suffix = "";
$feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1";
function parse_feed($feed) {
$stepOne = explode("<content type=\"html\">", $feed);
$stepTwo = explode("</content>", $stepOne[1]);
$tweet = $stepTwo[0];
$tweet = str_replace(”&lt;”, “<”, $tweet);
$tweet = str_replace(”&gt;”, “>”, $tweet);
return $tweet;
}
$twitterFeed = file_get_contents($feed);
echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);
?>

Thanks the awesome code from WP Hacks.

How to Create Meta Description Function and Meta Keyword Tags

If you want to create meta description function and meta keyword tags for your wordpress themes, open header.php file and then copy and paste the following code within <head> and </head>.

<meta name="description" content="
<?php if ( (is_home()) || (is_front_page()) ) {
echo ('Your main description goes here');
} elseif(is_category()) {
echo category_description();
} elseif(is_tag()) {
echo '-tag archive page for this blog' . single_tag_title();
} elseif(is_month()) {
echo 'archive page for this blog' . the_time('F, Y');
} else {
echo get_post_meta($post->ID, "Metadescription", true);
}?>">

Thanks the original function from Malcolm Coles.

How to Display the Total Number of Comments on Your Blog

Who don’t like to have comments on your blog? If your blog has many comments, it can be say that your blogs is popular, at least people like to interact with you to ask question and share information with you. If you really proud with your total number of comments on your blog, and want to show off to visitors.

To display the total number of comments on your blog, simple add the following code to your wordpress files.

<?php
$numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
if (0 < $numcomms) $numcomms = number_format($numcomms);
echo "There's ".$numcomms." total comments on my blog";
?>

Special thanks to PHP Magic Book for this awesome code.