There are many wordpress tweaks , hacks and tricks that we see everyday here are 10 tricks that I’ve seen lately and thought they are cool .
1- Display most commented posts with thumbnail .
![]()
Very simple and cool hack just paste the following code anywhere you want the list to show like your side bar file or footer file .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <?php $popular = new WP_Query('orderby=comment_count&posts_per_page=5'); ?> <?php while ($popular->have_posts()) : $popular->the_post(); ?> <?php $justanimage = get_post_meta($post->ID, 'Image', true); if ($justanimage) { ?> <img src="<?php echo get_post_meta($post-/>ID, "Image", true); ?>" alt="<?php the_title(); ?>" /> <?php } else { ?> <img src="http://an-alternative-image.jpg" alt="" /> <?php } ?> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <?php endwhile; ?> |
Change “http://an-alternative-image.jpg” to your default image url in case there is no thumbnail image linked to the post .
Source : wprecipes.com
2-Configure the trash

The Trash is a new feature since 2.9 . You can configure the number of days the posts stay in the trash from 30 to any number for example 7 .
1 |
Add the previous code to your functions.php them file .
Source : Wp Canada
3- Wrap Google Adsense In WordPress Posts Correctly

We will use shortcode api which is a very useful wordpress feature. Add the following to your functions.php theme file .
1 2 3 4 5 6 7 8 9 | function googlead_shortcode() { $adsensecode = 'GOOGLE ADSENSE SHORCODE GOES HERE'; return $adsensecode; } add_shortcode('googlead', 'googlead_shortcode'); |
now in your post you can use the shortcode [googlead] where ever you want google’s adsense to appear .
Source : aext.net
4-Create an event list

An events list is just what you would expect; a list of upcoming events, ordered by the date they are taking place on (Not the date they were written on!).
Michael Martin has written a very detailed tutorial on how to create an event list using wordpress .
Full Details in Problog Design
5- Remove private or protected from post title

When you password protect a post the word protected is added to the post title . Some might be ok with this but some might want to remove it .
Just add the following to your functions.php file .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | function the_title_trim($title) { $title = attribute_escape($title); $findthese = array( '#Protected:#', '#Private:#' ); $replacewith = array( '', // What to replace "Protected:" with '' // What to replace "Private:" with ); $title = preg_replace($findthese, $replacewith, $title); return $title; } add_filter('the_title', 'the_title_trim'); |
Source : Digging into wordpress
6- Google map shortcode

A cool shortcut to insert google maps inside your . Instead of pasting the iframe directly inside your post and as we all know the visual editor text will screw the code .Paste the following inside your functions.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | //Google Maps Shortcode function fn_googleMaps($atts, $content = null) { extract(shortcode_atts(array( "width" => '640', "height" => '480', "src" => '' ), $atts)); return '<iframe width="'.$width.'" height="'.$height.'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'.$src.'"></iframe>'; } add_shortcode("googlemap", "fn_googleMaps"); |
Now you add the map in your post using the following shortcode. Just specify the width , height and url
1 | [googlemap width="200" height="200" src="[url]"] |

Source : Digging into wordpress
7- Display twitter and feedburner counter

I’ve seen this before but I like how short and clean this code is .Just paste the code anyway you want the counter to show .
Feedburner
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <?php $url = file_get_contents('https://feedburner.google.com/api/awareness/1.0/Get FeedData?uri=YOUR FEED ADDRESS'); $begin = 'circulation="'; $end = '"'; $page = $url; $parts = explode($begin,$page); $page = $parts[1]; $parts = explode($end,$page); $fbcount = $parts[0]; if($fbcount == '') { $fbcount = '0'; } echo '<b> '.$fbcount.' Subscribers'; ?> |
Change YOUR FEED ADDRESS to your own feed address .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <?php $twit = file_get_contents('http://twitter.com/users/show/USERNAME.xml'); $begin = '<followers_count>'; $end = ''; $page = $twit; $parts = explode($begin,$page); $page = $parts[1]; $parts = explode($end,$page); $tcount = $parts[0]; if($tcount == '') { $tcount = '0'; } echo '<b> '.$tcount.' </b> Followers'; ?> |
Change USERNAME to your own username .
Source : Webm.ag
8- Remind your returning and new visitors to subscribe to your RSS

When a visitor come across your site and they start going through your old posts they will get a message to suggest subscribing to your rss feed .
1 2 3 4 5 6 7 8 9 | <?php if(is_paged()){ ?> <div id="rss-remind"> <p>Subscribe to <?php bloginfo('name'); ?> and never miss an entry:<br /><a href="<?php bloginfo('rss2_url'); ?>">All Posts<span> (RSS)</span></a> | <a href="<?php bloginfo('comments_rss2_url'); ?>">All Comments<span> (RSS)</span></a></p> </div><!-- #rss-remind --> <?php } ?> |
Source :ThemeShaper
9- Remove trackbacks from the total number of comments

By defualt wordpress count the number of vistors comments and the number of tracksbacks as the total number of comments . But as in this site we wanted to show only the total number of comments . You can change this by adding the following to your functions.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | add_filter('get_comments_number', 'comment_count', 0); function comment_count( $count ) { if ( ! is_admin() ) { global $id; $comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id)); return count($comments_by_type['comment']); } else { return $count; } } |
10-Split wordpress content into 2 or more column

Using this hack I can visualize many design ideas from splitting your content into 2 columns or more .
Add the following code to your functions.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // split content at the more tag and return an array function split_content() { global $more; $more = true; $content = preg_split('/<span id="more-\d+">< \/span>/i', get_the_content('more')); for($c = 0, $csize = count($content); $c < $csize; $c++) { $content[$c] = apply_filters('the_content', $content[$c]); } return $content; } |
Now go to you single.php file and comment the_content() by adding // before the line use the following code instead
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <?php // original content display // the_content('<p>Read the rest of this page »'); // split content into array $content = split_content(); // output first content sections in column1 echo '<div id="column1">', $content[0], '</div>'; // output remaining content sections in column2 echo '<div id="column2">', implode(array_shift($content)), '</div>'; ?> |
81 Inspiring Sketchs from Flickr
amazing tricks
Thank’s alot
Thanks for the mention
Thanks Abdallh
You are welcome McBonio
wow these trick can come quite handy. thanks!
You are welcome Saad. Thank you.
Excellent set of hacks, Fatma. I recommend adding wp_reset_query after the loop for your first hack, I explain why it’s important in my post here http://www.webtechwise.com/wp-reset-query-in-wordpress-hacks/
Thanks
very much appreciated…i jus bookmarked this info for future refference..any way thanks for the gr8 info. hope u wud publish more…