10 WordPress Hacks to Make your Life Easy

Published On August 27, 2008
167 Comments Leave a Comment

Displaying Gravatars in comments

To refresh your memory, Gravatars are little user images from Gravatar.com that are displayed against your comments in the theme (if the theme is built to support Gravatars). A lot of WordPress themes are built without the support of Gravatars. So, here is some help for you to add Gravatars in your theme. Open up your comments.php file from the theme folder. Find this piece of code :-

Replace the above code with the following code :-

=2.5)
echo get_avatar( $comment->comment_author_email, $size = '50', $comment->comment_author_link);?>


The above code will display the Gravatars. Now let us add some CSS to the style.css file for your theme.

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

When you check your theme again, you will see the Gravatar images against your comments.

Image Gallery in WordPress

All the versions of WordPress 2.5+ have inbuilt Image Gallery function where you can upload your images in a set and then insert the gallery either into your post or a new page.

But almost all the old themes(before 2.5) and many new ones do not have the integrated functionality. In order to add this feature, here is what you have to do :-

In your existing theme, open single.php and save it as image.php in your theme folder. Now open this image.php file in an editor and find the line that displays the post content. It should be somewhat in the following form. It can differ a bit but the function is called by the_content like this :-

Now insert the following code above the aforementioned code (the_content) :-

ID); ?>">ID, 'medium' ); ?>

post_excerpt) ) the_excerpt(); // this is the "caption" ?>

Insert the following code below the aforementioned code (the_content) :-


Now, add this CSS to your theme’s style.css file :-

/****************Image Gallery *********************/
.gallery {text-align:center;}
.gallery img {padding:2px; height:100px; width:100px;}
.gallery a:hover {background-color:#ffffff;}
.attachment {text-align:center;}
.attachment img { padding:2px; border:1px solid #999999;}
.attachment a:hover {background-color:#FFFFFF;}
.imgnav {text-align:center;}
.imgleft {float:left;}
.imgleft a:hover {background-color:#FFFFFF;}
.imgleft img{ padding:2px; border:1px solid #999999; height:100px; width:100px;}
.imgright {float:right;}
.imgright a:hover {background-color:#FFFFFF;}
.imgright img{ padding:2px; border:1px solid #999999; height:100px; width:100px;}

The above CSS code fixes the default gallery of WordPress which doesn’t look so good. So, now when you go and upload your images in a post or a page, go to the gallery option (after you have finished uploading all your images) and insert gallery into your post/page. That’s it!

Adding a “Subscribe to feed” message after every post

Many people use this kind of message to remind the readers to subscribe to their blogs and place them at the end of every post. This can be accomplished by using a simple plugin or you can do the following. If you want the message to show under all your posts on the homepage, open up index.php and just where your content finishes (the_content), add this line :-

If you enjoyed this post, make sure you subscribe to my RSS Feed

You can do the same for your single.php file in the theme folder which is used to display your individual posts.

Displaying Twitter messages on your blog

If you have a Twitter.com account and want to display the twitters that you make on your blog, here is what you have to do.

Login to your Twitter.com account. Go to this URL :- http://twitter.com/badges/html and choose your settings. Copy the code and paste it on your blog. You can paste it directly into your theme files or use text widgets to put them in a sidebar. They can also be styled through CSS.

Displaying Authors’ Bio

In a multi-user blog, it can be beneficial to show the Authors’ Bio under every single post for the users to read about the post author. This can be done using the Biographical Info in the Your profile setting under Users section of WP-Admin.

To integrate this bio, open up your single.php file and under the_content line (as before), add this code :-

Now, add the following CSS code to your style.css in the theme folder:-

.author{
color: #222222;
font-family: Arial;
font-size: 12px;
border:1px solid #CCCCCC;
width: 500px;
padding: 5px;
margin-top:10px;
margin-bottom:10px;
}

Now if you refresh your individual post pages, you will see the author’s info under the post content.

Categories drop down

To add a good looking drop down that will list all your existing categories, insert the following code in your blog template. You can do it either in your sidebar.php file or anywhere in the index.php. This is the code :-


]*)>#", "", $select);
echo $select;
?>

Archives drop down

Just like in categories, you can have your monthly archives listed in a drop down. Add the following code to your template files :-

Adding 125×125 Ads to your sidebar

Many people do not know how to integrate 125×125 banner ads into their theme sidebars. I will explain it to you. Save the following image to your desktop (this is a sample 125×125 banner that we will use) :-

Make a folder called “ads” in your theme folder (the theme in which you want to add these banners) and place this image (125.gif) in that new folder. Now, add the following code to your sidebar where you want the banners to appear :-

Advertising
Advertising



Finally, add the following CSS code to your style.css file :-

.bannerads {width:270px; margin:10px auto;}
.ad_125x125 {float:left; margin:0px 5px 10px 5px; width:125px; height:125px;}

When you refresh your theme, you will see two adjacent 125×125 banner ads in your sidebar. You can then change the images as you like and also the hyperlinks.

Displaying most commented (popular) posts

There is always an urge in bloggers to showcase their most popular posts or the posts with the most comments. This is how you can do it:-

Place the following code at the end of your header.php file in the theme folder. You can change the number of popular post titles that will be pulled from the database by altering the $no_posts variable in the code :-

', $after = '

', $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 . '' . $post_title . ' (' . $comment_count.')' . $after;
}
} else {
$output .= $before . "None found" . $after;
}
echo $output;
} ?>

Now, wherever you want to display the popular posts list, place the following code. You can do it in the sidebar or the index.php file.

Adding a Print Button to your posts

In order to enable your users to take printouts of your posts, you can provide them with a Print button on the blog. Open up your single.php file (for individual posts) from the theme folder and add the following code wherever you want to have the Print option:-

Print this Article

I hope that you liked these WordPress hacks and also hope that they make your life easy in some way 🙂

167 replies on “10 WordPress Hacks to Make your Life Easy”

adaswaney9405 Reply

Nice post. I learn something new and challenging on sites I stumbleupon everyday. It’s always helpful to read through articles from other writers and use a little something from other websites.

Natasha Reply

I’d like to thank you for the efforts you’ve put in writing this blog.
I am hoping to see the same high-grade blog posts from you in the future as well.
In truth, your creative writing abilities has inspired me
to get my own site now 😉

weed grinder Reply

Hey would you mind letting me know which hosting company you’re utilizing?
I’ve loaded your blog in 3 different internet browsers and I must
say this bblog loads a lot faster then most. Can you recommend a good intfernet hosting provider at a fair
price? Thanks a lot, I appreciate it!

Fred Reply

S? now we’re b?sch 800 series shx68r55uc m?ving into our second layer, and then we’re going to have to use thhe correct tool for the job.
Step 8 ?lace the link of batterties back iht? the Makita battery pack ba?k
to life. Where will that leave you? The?’ve got all sorts bosch
800 series shx68r55uc of holes.

visiteurs organiques Reply

It’s truly very complex in this full of activity
life to listen news on TV, thus I just use world wide web for that purpose, and take
the newest news.

best article spinner software Reply

Excellent post. I was checking continuously
this blog and I am impressed! Extremely helpful info particularly the last part 🙂 I care
for such information much. I was looking for this certain info for a very
long time. Thank you and good luck.

cm punk and daniel bryan segment Reply

Hi there everyone, it’s my first pay a quick visit at this web page, and paragraph is truly fruitful designed for me,
keep up posting these types of articles or reviews.

daniel bryan on cm punk Reply

Generally I do not read post on blogs, but I wish to say that this write-up very pressured me to take a look at and do so!
Your writing style has been surprised me. Thank
you, very great article.

mother teresa quotes Reply

Thanks in favor of sharing such a pleasant opinion, paragraph is fastidious, thats why i have read it entirely

daughter quotes Reply

My coder is trying to convince me to move to .net from PHP.
I have always disliked the idea because of the expenses.
But he’s tryiong none the less. I’ve been using Movable-type on numerous websites for about
a year and am worried about switching to another platform.
I have heard good things about blogengine.net. Is there
a way I can import all my wordpress content into it?
Any kind of help would be greatly appreciated!

Minecraft Premium Hacks Reply

Hey There. I found your blog using msn. This is a really well written article.

I’ll be sure to bookmark it and return to read more of your useful info. Thanks for the post. I’ll certainly comeback.

farmvill cheats Reply

Hi there! Quick question that’s entirely off topic. Do you know how to make your site mobile friendly? My web site looks weird when viewing from my iphone4. I’m trying to find a theme or plugin that
might be able to resolve this issue. If you have any recommendations,
please share. Cheers!

Hack Into Twitter User Accounts To Get Data Back Reply

Excellent items from you, man. I’ve bear in mind your stuff prior to and you’re just
extremely magnificent. I really like what you have obtained right here, certainly like what you are saying
and the way in which through which you assert it. You’re making it entertaining and you continue to take care of to stay it wise. I cant wait to learn far more from you. That is really a wonderful website.

Mark_Bennett Reply

The concept is simple. Gravatars are user images that are displayed against your comments in the WordPress themes. As majority of the WordPress themes don’t support Gravatars, you can add them by following the instructions given in the steps as explained in this post. Check out the 10 WordPress hack techniques and enjoy blogging!

Dollar Mill Reply

Thanks for these “hacks”. Though you can find some themes that already provide these features it never hurts some ol’fashioned php scripting and stuff. I am getting into it lately and your post provided me some useful insight.

prepaid handy tarife Reply

I created a new wordpress site and I don’t have a good design yet. But I hope your tutorial will help me a bit, but it looks complicated for a beginner like me.

Hot Girl Doing It Reply

What a great post. Thanks for the tips. I should be able to make my blog look better using these. Are there plug-ins for this stuff?

playstation 4 cheap Reply

interesting, I will definitely be trying these hacks out. Hopefully I can get some good use out of them!

Tioman Reply

Well I can say that your tutorial here just brighten my life today.. Thanks a lot! a lot of helpful stuff in this post 🙂

Josh Reply

@Dear Socrates:- displaying gravatars provides a more personal feel to your blog, letting readers have their picture rather than the generic one you choose. It may not make your life easier, but it is a great usability feature.

Having a subscribe to feed button under each of your posts gives the reader a quick and easy way to get updates from your site.. if I have to explain how that makes your (and the reader’s) life easier, than you’re just an idiot.

A lot of people use Twitter, a lot of people are interested in what their favorite bloggers are saying and doing on Twitter.. hence the relevance

and placing ads on your blog is a great way to generate revenue to keep the site going..

was that a sarcastic post, or are you really that dense?

Good article with a lot of simple tutorials that often escapes the attention of developers.

Vinod Srinivas Reply

Hello Jai, this is an interesting post. I usually tell my designers to prepare all this, but your post made things so much clearer. Good stuff!

Dear Socrates Reply

How’s “Displaying Gravatars” gonna make my life easier working with wordpress?
“Subscribe to Feed”? Twitter? Ads?

You gotta be kidding me, this is just a pile of shitty over-used mini-tutorials, and a plugin or two.
No real info.

Shubham Reply

hey..i was wondering how the AD box is placed and thanks to you…! Made my work easier..!!..can you give how can i add a 2 column add in the sidebar..!!..125×125..!! Thanks.!

Ryan Reply

Brilliant piece on how to display the most commented posts. Thank you!

I like to keep my template files clean, so I recommend that others place this function in their functions.php file (create this file if it does not exist for your theme). It works just fine outside of the header template.

Zack Reply

Great codes, especially Most Commented Posts. It’s very clever to re-counted comments by the comment_post_ID. I didn’t thought about this.

Tricyclic Antidepressants Reply

Very interesting article and very good blog. Very much interested to know)
I will add this blog to RSS Reader

megan fox Reply

Sign: umsun Hello!!! rcuwwymhyw and 3544ssgfhphzye and 9009I love your site. 🙂 Love design!!! I just came across your blog and wanted to say that Ive really enjoyed browsing your blog posts.

Todor Rangelov Reply

Hi i need a function like yours Displaying most commented (popular) posts.

But i need most comented posts for current category. I avaery categori i retrieve a list of all posts in this category how to order them by comment count?

Any help an ideas?

Veronica Reply

Hi. In the right light, at the right time, everything is extraordinary.
I am from Eritrea and learning to speak English, tell me right I wrote the following sentence: “Learning proper introductions not only enhances your business savvy but boosts your self confidence.”

Best regards :-), Veronica.

Baldraiff Reply

hi there!
I made with photoshop glitter myspace pictures.
take a look at them:
http://tinyurl.com/5pde2x
Thank you for your website 😉 xxoxo

bbrian017 Reply

wow I have added this page to my favs I wouldn’t mind doing a few things mentioned here including the member bio!

Nice hack thanks man

Markus Zilgalvis Reply

@Chada:- But what if you would like to modify the printed pages layout or something… ? This print button would be quite usefull.

elf_fu Reply

Thank you very much, Jai! I have always wondered how to do a lot of the things which you have listed off here, and this post clarifies everything in an easy and great manner to follow!

Appreciate it very much!

suicidalsam Reply

wow, I found the hack I was looking for after a very long time. I have been wonder how to place 125 banner ads on my sidebar and this post of yours really helped me out and it is very easy to do. thanx again.

Edi Susanto Reply

Thanks for sharing those great tricks. Inspire by trick put category list into drop down, how do I put my tag list into a drop down?

Thanks for helping….

Team Nirvana Reply

Thanks for conglomerating the details at a single point and presenting to us. I would also request you to post about any plugin which would enable the wordpress users/readers to download the post as a PDF file.

Thanks for the support.

April Hollands Reply

Thank you thank you thank you!! I finally have Gravatars working thanks to your very easy-to-follow steps (if only WordPress.org has such user-friendly documentation).

Young Reply

@Young:-
there are some wrong words in my previous comments, sorry and will be more careful next time. Look forward to your advice.

Charl Reply

This is great! I am beginning a web project soon for a photo gallery and your tips here would come really handy. Many, many thanks!

Website Design Reply

This is exactly why I like wordpress so much. You can edit / hack it up, etc without anyone getting angry. It’s awesome.

Bryan Reply

I love the theme. Can anyone tell me how to add who submitted the post. I have a blog with multiple author but dailypress doesn’t show who submitted the post.

Yan Shall Blog Reply

What a great collection of hacks! I attempted to add the most popular post but encountered this error

Parse error: syntax error, unexpected ‘{‘ in /home/……/public_html/wp-content/themes/sketchd/header.php on line 67

What could be the problem? I have added the code to my header.php and the php code on my footer.

Appreciate your guide on this. Thank you…

Yan

Manish Mohan Reply

Can you also provide code for showing Author names in the side bar along with the number of posts by each author? I manage a team blog and it would be great to have this. Each name could hyperlink to the posts by that author.

Authors
name1 (#)
name2 (#)

Dgold Reply

I used 2 of the tips. I used your code to make my old theme compatible with the new WP galleries. I’ve put in the code, now I am going to upload pictures and try to post a gallery. I hope it works!

Next I used your Twitter calling code. Easy enough, I put my latest Twitter message right beside where I already had a Twitter chiclet.

Luckily Twitter warned me to put the “script call” in my WordPress Footer. That way, if Twitter happens to be down for the day, my page will still load.

On your Print tip, I think the thing that’s missing is a printable stylesheet. A lot of times the regular webpage, with ads and colors and borders, is too much to print. I use Gamerz’ WP-Print plugin for this.

Ant Harper Reply

I have already implemented some of these on my blogs via plugins, but to be able to edit the code yourself is always useful. Thanks for the article!

Ian Blackford Reply

A friend of mine is really happy with his theme but it doesn’t show gravatars in the comments, I just pointed him at this post. Thanks for the great tips.

Chada Reply

nice work!

I think that the Print Button is not necessary because that there is already a Print selection in the browses’ File list.

Manish Mohan Reply

Brilliant!!! Thank you. Great post to save and keep referring to every now and then to tweak my WordPress blog. Keep it up!

Leave a Reply to BoyGJ.COM Cancel reply

Your email address will not be published. Required fields are marked *