Lately I have been on this wordpress theme kick. I have created a couple of new themes currently in the process of being added to the wordpress themes section. And since I never really worked with wordpress too much, I spent some time looking at “how to’s” and other peoples theme development. Some I found great, some I didn’t. All in All the power of wordpress is amazing and with that being said, I decided to put a little list together. A small roundup of some hacks and enhancements that I found useful and hopefully you do too.
Adding Author Avatar to posts
the ‘55′ is basically the width. So you can change that to what you want according to your design.
1 | <?php echo get_avatar( get_the_author_email(), '55' ); ?> |
Adding User Comment Avatars
the ‘40′ is basically the width. So you can change that to what you want according to your design.
1 | <?php if(function_exists('get_avatar')) { echo get_avatar($comment, '40'); } ?> |
Highlight Admin Comments
Replace this:
1 | <li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>"></li> |
For this:
2 | <li class="<?php if ($comment->user_id == 1) $oddcomment = "authorCommentBox"; echo $oddcomment; ?>"></li> |
CSS:
2 | .authorCommentBox{ background-color: #ecf584 !important; } |
Simple Social Network Links
Had some issues with the title of the post including
%20
and such, so wrote something quick to handle that Plus creating a bit.ly URL on the Fly for the post:
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 28 29 30 31 32 | <?PHP /* make a URL small */ function make_bitly_url($url,$login,$appkey,$format = 'xml',$version = '2.0.1') { //create the URL $bitly = 'http://api.bit.ly/shorten?version='.$version.'&longUrl='.urlencode($url).'&login='.$login.'&apiKey='.$appkey.'&format='.$format; //get the url //could also use cURL here $response = file_get_contents($bitly); //parse depending on desired format if(strtolower($format) == 'json') { $json = @json_decode($response,true); return $json['results'][$url]['shortUrl']; } else //xml { $xml = simplexml_load_string($response); return 'http://bit.ly/'.$xml->results->nodeKeyVal->hash; } } /* usage */ //$short = make_bitly_url('http://yoursite.com','USERNAME','API-KEY','json'); //echo 'The short URL is: '.$short; // returns: http://bit.ly/11Owun ?> <?php $permaURL = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $post_url = make_bitly_url($permaURL,''USERNAME','API-KEY','json'); ?> |
Add This:
1 2 3 4 5 6 7 | <a href="http://twitter.com/home?status=@that_agency <?php the_title();?> <?php echo $post_url; ?>">Twitter</a> <a href="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>&t=<?php the_title(); ?>">Facebook</a> <a href="http://delicious.com/save?url=<?php the_permalink() ?>&title=<?= urlencode(the_title()); ?>">de.licio.us</a> <a href="http://digg.com/submit?phase=2&url=<?php the_permalink() ?>&title=<?= urlencode(the_title()); ?>" rel="external">Digg</a> <a href="http://stumbleupon.com/submit?url=<?php the_permalink() ?>" rel="external" title="StumbleUpon">StumbleUpon</a> <a href="http://technorati.com/faves?add=<?php the_permalink() ?>" rel="external" title="Technorati">Technorati</a> <a href="http://scriptandstyle.com/submit?url=<?php the_permalink() ?>&title=<?= urlencode(the_title()); ?>">Script&Style</a> |
Using Normal Quotes Instead of Curly Quotes
Add this to your functions.php (If you don’t have one, then create one.)
1 | <?php remove_filter('the_content', 'wptexturize'); ?> |
Display Feedburner Subscriber Count
via (wprecipes)
1 2 3 4 5 6 7 8 9 10 11 | <?php $fburl="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=feed-id"; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $fburl); $stored = curl_exec($ch); curl_close($ch); $grid = new SimpleXMLElement($stored); $rsscount = $grid->feed->entry['circulation']; echo $rsscount; ?> |
As you can see, wordpress offers a wide variety of integration to customize your own theme. This list is just the tip of the iceberg. There are so many other things, that wordpress is able to do.
Do you know of any more? Let me know.
Tags: wordpress, Wordpress Hacks




Comment By: Sarah
September 29th, 2009 at 6:04 pm
I’m about to create my first WP theme and this was very helpful. Thanks!
Comment By: amir
March 9th, 2010 at 12:15 am
very useful tips. thanks for posting rich. I’m trying a couple of these hacks out tomorrow