Stop Using WordPress Plugins – Top 3 WordPress Hacks

3 Comments
Tags: , , ,
Posted 03 Sep 2008 in WordPress

WordPress WednesdaysThere is some evidence that the more plugins you use on your WordPress installation, the slower your website will load.

So, ditch some of those plugins and use these three WordPress hacks to get the same functionality and at the same time improve your page load time!

First up is Gravatar, the globaly reconized avatar that ‘follows’ you no matter where you go online. Yes, there are WordPress plugins available that make adding Gravtars oh so simple, but be adventurous and set up Gravatars on our own!

To begin, navigate to Design > Theme Editor > comments.php

Find this code:

<?php comment_text() ?>

And replace with:

<div class="gravs">
<?php if (get_bloginfo('version')>=2.5)
echo get_avatar( $comment->comment_author_email, $size = '50', $comment->comment_author_link);?>
<?php comment_text() ?>
</div>
<br clear="all" />

Save the comments.php file, and open your style.css file. Add the following code:

.gravs {margin-top:20px;}
.avatar {float:left; margin-right:5px; margin-bottom:5px; padding:3px; border:1px solid #999999;}

Save the style.css file, and refresh your homepage. You should now see the Gravatars next to all comments on your blog!

Now, let’s get your most popular posts onto your blog’s sidebar! First, open header.php and paste the following code at the bottom of the file:

<?php function most_popular_posts($no_posts = 5, $before = '<li>', $after = '</li>', $show_pass_post = false, $duration='') {
global $wpdb;
$request = "SELECT ID, post_title, COUNT($wpdb->comments.comment_post_ID) AS 'comment_count' FROM $wpdb->posts, $wpdb->comments";
$request .= " WHERE comment_approved = '1' AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish'";
if(!$show_pass_post) $request .= " AND post_password =''";
if($duration !="") { $request .= " AND DATE_SUB(CURDATE(),INTERVAL ".$duration." DAY) < post_date ";
}
$request .= " GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC LIMIT $no_posts";
$posts = $wpdb->get_results($request);
$output = '';
if ($posts) {
foreach ($posts as $post) {
$post_title = stripslashes($post->post_title);
$comment_count = $post->comment_count;
$permalink = get_permalink($post->ID);
$output .= $before . '<a href="' . $permalink . '" title="' . $post_title.'">' . $post_title . '</a> (' . $comment_count.')' . $after;
}
} else {
$output .= $before . "None found" . $after;
}
echo $output;
} ?>

Save the file and open the file for where you want to display your most popular posts – sidebar.php, index.php, footer.php, etc. – and paste this code:

<?php most_popular_posts(); ?>

Again, save the file, refresh your homepage and now you can see your most popular posts!

And last, but definitely not least, add a “subscribe” reminder directly below each post without using a plugin like What Would Seth Godin Do.

Open index.php, and look for the code (the_content) – paste the following code directly afterward, and remember that you can tweak the colors using a color picker, the font face and even the wording. Don’t forget to add the link to YOUR RSS feed!

<div style="padding:5px; border:1px solid #999999; margin-top:10px; background-color:#FFF8AF;">
If you enjoyed this post, make sure you subscribe to my <a href="RSS LINK HERE">RSS Feed</a>
</div>

Don’t forget to save your changes!

If you like, you can also add this code to single.php, which will add this gentle reminder to subscribe to each single post page. This is helpful if you only show excerpts of posts on the homepage.

Do you have any tips for WordPress code tweaks? Let’s hear it in the comments!


WordPress Wednesdays features posts about plugins, themes and general usage of WordPress, the world’s most popular content management system!

Special thanks to Blog Oh Blog for their complete tutorial on WordPress Hacks and Fabworker for the “Subscribe to a feed” code.

Blog Widget by LinkWithin

3 Trackbacks/Pingbacks

  1. Ultimate Geek Girl Review & Contest | Giveme Contests 16 09 08
  2. Use RSS Footer to Personalize your RSS Feed : ultimate geek girl 17 09 08
  3. Wordpress PHP Code Snip - Assign image to post ID | Pingable.org :: Resources for Web Developers 31 10 08