Jayesh Patel
Filed under - Development, PHP, Web Designer Help, WordPress
No Comments so far. Add yours now

This technique utilizes the new feature added in WordPress 2.9 to add Thumbnails to each post and you can display them anywhere in the loop.

11. Display Feedburner Subscriber Count as Text

Have you ever been to a site that is not using Feedburner button and is still showing subscriber count? Well they are probably using the trick we are about to share. Most designers use this trick to have custom styling and avoid the annoying feedburner button.

Simply copy and paste this code anywhere you like most likely sidebar.php

    <?php
    //get cool feedburner count
    $whaturl="http://api.feedburner.com/awareness/1.0/GetFeedData?uri=your feedburner id";

    //Initialize the Curl session
    $ch = curl_init();

    //Set curl to return the data instead of printing it to the browser.
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    //Set the URL
    curl_setopt($ch, CURLOPT_URL, $whaturl);

    //Execute the fetch
    $data = curl_exec($ch);

    //Close the connection
    curl_close($ch);
    $xml = new SimpleXMLElement($data);
    $fb = $xml->feed->entry['circulation'];
    echo $fb;
    //end get cool feedburner count
    ?>

You can wrap it around in styling to make it look like however you want.

12. Display Twitter Follower Count as Text

There are users who absolutely hate buttons like Feedburner buttons or Twittercounter buttons. Are you one of them? Do you want to display your twitter count as text, so it blends in to your new custom design? Well then this hack is just for you.

First you would need to create a file twitter.php and paste the following code in there:

<?php
$tw = get_option("twitterfollowerscount");
if ($tw['lastcheck'] < ( mktime() – 3600 ) )
{
$xml=file_get_contents('http://twitter.com/users/show.xml?screen_name=wpbeginner');
if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
$tw['count'] = $match[1];
}
$tw['lastcheck'] = mktime();
update_option("twitterfollowerscount",$tw);
}
echo $tw['count'];
?> 

Make sure to replace wpbeginner with your twitter name.

Then Simply place this code anywhere you want to display this:

<?php include("twitter.php"); ?>

Source

13. Create Your Own Private Twitter Site using WordPress

Create Your Own Private Twitter Site Using WordPress

14. Control When Your Posts are Available via RSS

Control When Your Posts are Available via RSS

There are times when you publish a post and suddenly find an error. You can go back in the admin panel and change it, but it is already published in the feeds. With this hack, you can put a delay of as many minutes as you like, so you can double check the post live.

Simply open your functions.php and add the following code in there:

    function publish_later_on_feed($where) {
    global $wpdb;

    if ( is_feed() ) {
    // timestamp in WP-format
    $now = gmdate('Y-m-d H:i:s');

    // value for wait; device
    $wait = '10'; // integer

    // http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
    $device = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR

    // add SQL-sytax to default $where
    $where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
    }
    return $where;
    }

    add_filter('posts_where', 'publish_later_on_feed');

Change the time from 10 minutes to whatever you like.

15. Allow Multiple Authors to be Associated with One Post

If you run a multi-author blog and have a post coming up that more than one author has contributed to, you can use this trick. This trick is being used by many top multi-author blogs.

Co-Author WordPress Blogs

Simply Download a Plugin called Co-Authors or Co-Authors Plus

16. Change the Default Gravatar Button

Good Bye Mystery Man

The default mystery man is really annoying for most users. Plus if you have one more chance of branding your blog, then why not do it. Changing your default gravatar lets you brand your blog more. With this snippet below you can change your default gravatar.

First you need to open your functions.php which is located in your template folder. If you don’t have one then create one and insert the following code:

    add_filter( 'avatar_defaults', 'newgravatar' );

    function newgravatar ($avatar_defaults) {
    $myavatar = get_bloginfo('template_directory') . '/images/gravataricon.gif';
    $avatar_defaults[$myavatar] = &quot;WPBeginner&quot;;
    return $avatar_defaults;
    }

In the code the image is being extracted from the theme directory and it is called gravataricon.gif obviously you will change it to your image name. Where it says WPBeginner, that is the name of the avatar of how it will show in your admin panel options area.

Gravatar Settings

Head over to your admin panel and click Settings > Discussion and change the icon, and now you have a branded comment area with your logo.

17. Display Random Header Images in WordPress

Random Header Images

Most blog designs get boring if they have a huge header picture and it is static. This is when this tutorial comes in to make your header images dynamic because it rotates on each visit. You can select as many images as you want to rotate randomly. It brings life to a blog.

First you need to name your images in this format:

  • headerimage_1.gif
  • headerimage_2.gif
  • headerimage_3.gif

You must separate the name with an underscore. You can change the headerimage text to himage or anything you like.

Once you have done that paste the following code in your header.php where you would like the images to be displayed or in any other file.

<img src="http://path_to_images/headerimage_<?php echo(rand(1,3)); ?>.gif"
width="image_width" height="image_height" alt="image_alt_text" />

Make sure that you change the number 3 if you decide to do more than 3 images. This code is not exclusive for WordPress, it will work with any php based platform.

18. Only Display Certain Categories in a Menu

Display Certain Categories in a Menu

In many cases, users only want to display certain categories in their navigation menu at the top of the page. There are limited spots, that can only be filled by top categories, but if you use the default wp_list_categories code, it will show all categories. This is why this hack below comes in very handy when you want to create a navigation menu and only display certain categories.

<ul class="navmenubar" style="float:left; width:730px;">
<?php wp_list_categories('orderby=name&include=7,9,19,16,1,5,17,23'); ?>
</ul> 

Note, you can also change the ‘include’ text to ‘exclude’ and show all categories and exclude those that you don’t want displayed. The numbers displayed in the code are the category IDs. Remember since WordPress shows categories in a list format, you will need to edit the CSS in order to make it work.

19. How set an Expiration Date for Your Posts

Set an Expiration Date for Your Posts

This hack comes becomes very useful when you are running a contest because you might be posting information such as clues or hints that you don’t want to stay up for ever. Instead of manually removing the article, you can just make it expire automatically. It also works if you have a product that you are offering a discount on. You posted it on your blog, but you don’t want that discount to stay on your blog after its over. So you can remove it automatically with this code.

All you need to do is replace your WordPress Loop with this code:

    <?php
    if (have_posts()) :
    while (have_posts()) : the_post(); ?>
    $expirationtime = get_post_custom_values('expiration');
    if (is_array($expirationtime)) {
    $expirestring = implode($expirationtime);
    }

    $secondsbetween = strtotime($expirestring)-time();
    if ( $secondsbetween > 0 ) {
    // For example…
    the_title();
    the_excerpt();
    }
    endwhile;
    endif;
    ?> 

Once you have done that, you can use custom fields when writing a post to set an expiration date. Make sure you select the key “expiration” and use the the following date format: mm/dd/yyyy 00:00:00

Now this hack does not remove or unpublish the article instead it just excludes the article from being displayed in the loop.

20. Delete Posts Revisions from Your Database

Delete Batches of Post Revisions

WordPress has a lot of good features and one of them is Post Revisions. This was included in WordPress 2.6, even though this is a good feature, it can cause some problems. One of them is increase the size of your database. Depending on how long it takes you to write a post, you might have as many as fifty post revisions. Now you can manually delete them, or you can run a simple query which we will show you in this post and get rid of all these useless revisions.

First thing you need to do is login to your phpMyAdmin and select your WordPress Database.

Click on the SQL Button and enter the following query:

DELETE FROM wp_posts WHERE post_type = "revision";

In this code basically we looked up a table wp_posts and removed every post that had a post_type revision associated with it. Now depending on the size of your database, this may save you a lot of space.

21. Create a Membership Directory using WordPress

Create a Membership Directory using WordPress

The end result is a moderated directory that allows members to enter information about themselves. Live Example.

22. Create a Peel Away Effect in WordPress

Peel Away Effect in WordPress

Have you arrived at a site where you see this page peel effect that some bloggers have. They are advertising their recent ebook, or some other product, and you want to do the same. Well then Hongkiat Blog has a great tutorial about this. The tutorial eliminates the use of plugin, but if you want an alternative option. Page Peel Plugin can get you the same functionality with a lot less work.

23. Custom CSS Stylesheet for Individual Posts

There are sites that use custom stylesheet for individual posts. Do you want to know how you can do it also? It is very simple. This is accomplished by the use of Custom Fields.

First you will need to open your header.php and insert this code somewhere in between <head></head> codes.

<?php if (is_single()) {
$customstyle = get_post_meta($post->ID, 'customstyle', true);
if (!empty($customstyle)) { ?>
<style type="text/css">
<?php echo $customstyle; ?>
<style>
<?php }
} ?> 

Once you have done that you can add a custom field in each post with the name customstyle and add the css codes in there.

For example if you want the a certain image to have border you can add:

#coolimageclass{border: 5px solid #ccc;}

Use the format above and you now have custom CSS for your single posts.

24. Easily Add Custom Header, Footer, or Sidebar on Different Categories

Did you ever come across a site that is using different header or sidebar for some categories? Well this is how you can accomplish that as well.

To call a particular header, you will need to open your index.php and replace your normal header code with this one:

<?php if (is_category('Blogging')) {
get_header('blogging');
} else {
get_header();
} ?>

This code above is basically telling WordPress that if someone opens the category called “Blogging” then WordPress needs to display a file called header-blogging.php if it exist. If it does not exist, or if the category is not blogging, then WordPress displays the default header file.

To get a separate sidebar for each all you need to do is add the following code:

<?php if (is_category('Blogging')) {
get_sidebar('blogging');
} else {
get_sidebar();
} ?>

The code above will look for sidebar-blogging.php to replace the default footer file if the category is Blogging.

To get a separate footer for each category all you need to do is add the following code:

<?php if (is_category('Blogging')) {
get_footer('blogging');
} else {
get_footer();
} ?>

The code above will look for footer-blogging.php to replace the default footer file if the category is Blogging.

25. Create a Custom Login Page Design for WordPress

Custom WordPress Login Page

Do you have a multi-author site, or a community site powered by WordPress? Do you want to rebrand the login page design? Then this tutorial is just right for you.

26. Place Content Only in your RSS Feeds

RSS Footer

Do you have a lot of RSS Subscribers? Well then maybe you want to monetize it just like tons of other users who are doing it. The plugin called RSS Footer lets you add content to your RSS Feeds. You can style it however you like.

27. Disable HTML in WordPress Comments

Did you ever see in your SPAM folder, how many comments have tons of HTML codes which is basically links. That is how most spammers add links. But you can disable HTML in WordPress Comments to be functional. So if someone uses the strong code, it will not bold the text etc.

All you have to do is simply open your functions.php and add the following code:

    // This will occur when the comment is posted
    function plc_comment_post( $incoming_comment ) {

    // convert everything in a comment to display literally
    $incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);

    // the one exception is single quotes, which cannot be #039; because WordPress marks it as spam
    $incoming_comment['comment_content'] = str_replace( "'", '&apos;', $incoming_comment['comment_content'] );

    return( $incoming_comment );
    }

    // This will occur before a comment is displayed
    function plc_comment_display( $comment_to_display ) {

    // Put the single quotes back in
    $comment_to_display = str_replace( '&apos;', "'", $comment_to_display );

    return $comment_to_display;

Source – The original author also offers a plugin that you can download from his site.

28. Add Digg Buttons in Your Posts using Custom Fields

Doesn’t it get annoying posting digg buttons on your articles every time. But you don’t want to display them on every page by default because some articles are not digg worthy. Well this solution would be very helpful then. In this plugin, you will add the codes in your single.php once, and in each article that you want to display the button, you will just have to enable it using the custom field.

First open your single.php and find a code that looks like this:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

Replace it with:

<?php if (have_posts()) : while (have_posts()) : the_post();
// check for digg button for single page
$digg = get_post_meta($post->ID, 'Digg', $single = true);
?>

Now you need to add the following code within the loop anywhere you like:

<?php // if there's a single page digg button
if($digg !== '') { ?>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
<?php } // end if statement
// if there's not a digg button
else { echo ''; } ?>

You may wrap it around with any styling that you want. Save the single.php and upload it to your theme folder.

Now when writing a post if you want to add a digg post simply add a custom field like shown in the screen shot below:

Add a Digg Button in Your WordPress using Custom Field

Whenever you specify this custom field, WordPress will display a digg button on your post.

29. Display Latest Sticky Posts in WordPress

Assuming that you have already created a custom page template and/or already have The Loop ready, paste the following code before the loop.

    <?php
    /* Get all sticky posts */
    $sticky = get_option( 'sticky_posts' );

    /* Sort the stickies with the newest ones at the top */
    rsort( $sticky );

    /* Get the 5 newest stickies (change 5 for a different number) */
    $sticky = array_slice( $sticky, 0, 5 );

    /* Query sticky posts */
    query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );
    ?>

This code can very well be used in featured slider, or any other advanced feature that you would like to display on your site. This snippet is mostly geared toward a WordPress site that has a custom homepage or a magazine style look.

The credit to this code goes to Justin Tadlock and partially to Nathan Rice for coming up with the array slice solution.

30. Display a Retweet Button On Your Site

Add a Retweet button in WordPress

With Twitter getting so much exposure, as a blogger you should already be using it to your advantage. Power of twitter is like no other because it is word of mouth advertising. To make this easier on your readers, what you can do is place a prominent retweet button, so they can retweet the article with one click. Not only just that, but you should make it the way so you can track the retweets as well. That is where tweetmeme widget comes in.

In this tutorial we will have you create a button that will link to the text in the following format:

RT @yoursitename Title of the Post – Link

Add the following code in the template file of your choosing most likely single.php

For the Large Button:

<script type="text/javascript">
tweetmeme_source = 'wpbeginner';
</script>
<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"> </script>

For the Compact Button:

<script type='text/javascript'>
tweetmeme_style = "compact";
tweetmeme_source = 'wpbeginner';
</script> 

Remember to change the source to your twitter account name, this way you will not only promote your account to get more followers, but your article will be promoted as well.

31. Display Categories in a Drop Down Menu

Display Certain Categories in a Dropdown Menu

Some blogs have a lot of categories which they can’t display in their sidebar. Or some bloggers do not want to take up a lot of space displaying categories. This option allows them to have a select menu, dropdown menu, for categories. See WordPress Codex for details.

<form action="<?php bloginfo('url'); ?>/" method="get">
<?php
$select = wp_dropdown_categories('show_option_none=Select Category&show_count=1&orderby=name&echo=0&selected=6');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
echo $select;
?>
<noscript><input type="submit" value="View" /></noscript>
</form> 

32. Show Category Icons

Show Category Icons

Pictures make a site more lively which is a given which is why blogger might want to associate pictures with their category. This plugin lets you associate a specific icon of your choice to a designated category. You can use this plugin to list categories by icon with or without names, and much more.

Download this Plugin

33. Display the most Recent Post from a Specific Category

Did you see sites with a magazine style theme who are displaying posts from a specific category. Sometimes only the most recent post. Well you can do this too easily.

    <?php
    query_posts('showposts=1&cat=3');
    while(have_posts()) : the_post();
    ?>
    <ul>
    <li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>

    <ul><li><?php the_content(); ?></li>
    </ul>
    </li>
    </ul>
    <?php endwhile; ?> 

Add the above code anywhere you like in the template. Make sure you change the category ID and you can change the number of posts displayed as well if you want.

34. Future Post Calendar

This plugin adds a simple month-by-month calendar that shows all the months you have future posts for (and the current month no matter what), it highlights the days you have posts for, and as an added bonus if you click a day the Post Timestamp boxes change to that day, month and year.

Future Post Calendar

35. Modify Excerpt Length and More Tags

WordPress lets you display Excerpts, but up until version 2.9 you could not control the excerpt length. With the following code, you can increase the length from default 55 words to as many words as you like. Open your functions.php file and add the follwowing codes in there:

    // Changing excerpt length
    function new_excerpt_length($length) {
    return 100;
    }
    add_filter('excerpt_length', 'new_excerpt_length');

    // Changing excerpt more
    function new_excerpt_more($more) {
    return '…';
    }
    add_filter('excerpt_more', 'new_excerpt_more');

Change the 100 word limit to the count that you desire.

36. Display Author’s Twitter and Facebook Information on their Profile Page

WordPress has fields for fields for author contacts, but it has not been updated in ages. So by default you do not have an ability to add author’s twitter or facebook. With this hack you can add this information on their profile page.

First open your functions.php and paste the following code:

    <?php
    function my_new_contactmethods( $contactmethods ) {
    // Add Twitter
    $contactmethods['twitter'] = 'Twitter';
    //add Facebook
    $contactmethods['facebook'] = 'Facebook';

    return $contactmethods;
    }
    add_filter('user_contactmethods','my_new_contactmethods',10,1);
    ?>

The above code will add two extra fields on your user-edit page named twitter and Facebook. You can display the code with the following code in your author.php file.

<?php echo $curauth->twitter; ?>

Source: Joost De Valk

37. Create a Contributors Page that lists Author with Avatars and Other Details

Create Author List with Avatars and Other Details

Do you run a multi-author blog? Do you want to create a content-rich contributors page. This tutorial is just for you.

38. Display Twitter Avatars in Comments

You probably have seen many sites using gravatars in comments because that is built-in. But there are some sites that are using twitter avatars, and if you are wondering how they are doing it then this trick will help you.

Twitter Avatars in WordPress Comments

Download the Plugin and follow this article for the instructions.

39. Create a Business Directory using WordPress

Create a Business Directory Using WordPress

This plugin lets you create a business/web directory which allows users to submit their links or other information.

40. Create a SIMILE Timeline using WordPress

Create a Timeline Using WordPress

41. Display Breadcrumb Navigation in WordPress

Have you seen sites that have a breadcrumb like ebay? Did you want to do it on your site? If you do then this plugin is just right for you. It has plenty of SEO advantage and it is extremely helpful to users.

Display Breadcrumb Navigation in WordPress

42. Create Your Own Facebook Application for Your WordPress Site

Facebook Application for Your WordPress Site

Did you ever want to utilize the power of Facebook by creating your own Application? Well WordPress lets you create an application for your blog. Follow this tutorial and utilize the power of facebook.

43. Display Most Recent Comments with Gravatars

Have you seen sites that display most recent comments in their sidebar with user gravatars. Well this can be done easily with these codes. Simply paste the following code anywhere you want to display the most recent comments.

    <?php
    $query = "SELECT * from $wpdb->comments WHERE comment_approved= '1'
    ORDER BY comment_date DESC LIMIT 0 ,5";
    $comments = $wpdb->get_results($query);

    if ($comments) {
    echo '<ul>';
    foreach ($comments as $comment) {
    $url = '<a href="'. get_permalink($comment->comment_post_ID).'#comment-'.$comment->comment_ID .'" title="'.$comment->comment_author .' | '.get_the_title($comment->comment_post_ID).'">';
    echo '<li>';
    echo '<div class="img">';
    echo $url;
    echo get_avatar( $comment->comment_author_email, $img_w);
    echo '</a></div>';

    echo '<div class="txt">Par: ';
    echo $url;
    echo $comment->comment_author;
    echo '</a></div>';
    echo '</li>';
    }
    echo '</ul>';
    }
    ?> 

To get more or less than 5 comments, change the number 5 on line 2.

Source: WPRecipes

44. Greet Each User with Appropriate Message

Greet Each User with Appropriate Message

If you like to read blogs, then you must have seen this on at least one blog. You can select to display a specific message to different users depending on the source they arrived at your blog. So for example, if someone comes to your blog via twitter, this plugin will show them a different text.

Download this Plugin: WP Greet Box

45. Display Different Social Media Submit Buttons

Many if not all blogs has some type of social media integration on their site. Most sites though have different social media sites button on their single pages, so they can get more votes. There are many plugins that can add this feature in your WordPress Blog. But this can also be done manually. Anyone who is curious should use this social media theme guide as a reference.

46. Digg/Bury Blog Comments

Digg-Bury Blog Comments

Did you ever wish that there was some type of voting system on your blog comments. Well this plugin has just what you want. It allows users to vote up or vote down the comment.

47. Redirect Your User’s Attention

Have you been to a WordPress site where you make your first comment and you are redirected to another page? If not, then you are at one right now. We redirect our first commentators to a Thank You Page. But this Plugin can be used for the sake of advertisement also if you want your users to know about your new product. Simply Download a plugin called Comment Redirect.

Comment Redirect

48. Add Twitter ID Field in WordPress Comment Form

Add Twitter Field in WordPress Comment Form

Many top sites including Mashable and Techcrunch are doing this. They have an additional twitter field in their comment forms. So users can put their twitter profile if they want to. This can be done in 5 easy steps if you follow the tutorial by clicking on the hack title.

49. Display Guest Author’s Name via Custom Field

Many Blogs are now having guest posts on their site. Some of these guest authors are one-time only authors, so there is no point in creating a separate profile for them just so you can display their name in the post. The smarter way to do this is by using the following code.

Open you single.php, or page.php in your template and add the following code where you display the author name:

<?php $author = get_post_meta($post->ID, "guest-author", true);
if ($author != "") {
echo $author;
} else {
the_author();
} ?>

This code will look for the custom field called guest-author if it is found, then it will display that name, otherwise it will display the_author function meaning the person who actually published it meaning you.

Note: You might have to remove the original the_author function before you place this.

Source: WPRecipes

50. Display Most Recent Tweet in WordPress

Twitter is getting very famous among bloggers. Many bloggers are now displaying their most recent tweet on their blog. If you want to display your most recent tweet on your blog simply place this code where you want to display it in your WordPress theme.

    <?php
    $username = "TwitterUsername"; // Your twitter username.
    $prefix = ""; // Prefix – some text you want displayed before your latest tweet.
    $suffix = ""; // Suffix – some text you want display after your latest tweet.
    $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);
    ?> 

e

Make sure to change the username in the first line.

51. Improve Your WordPress SEO

This is a detailed guide that will help you improve your WordPress SEO. We compiled it a while back and it has received many positive reviews from users.

52. Add Email This Article Option to Your WordPress Posts

Have you seen a site that gives you an option to email the article to your friend. If you have read a newspaper online, then you have. WordPress has a similar feature for the posts. You can add it by simply enabling a plugin called Email This.

Email This Article Plugin for WordPress

Once you have installed and updated the settings to your desire, simiply add this code in your single.php inside the loop.

    <?php if(function_exists('wp_email')) { email_link(); } ?>

This code will put a printer icon / link to every post page.

53. Create a Resourceful 404 Page Design

Best 404 Page Design

The above tutorial lists some of the elements that you should have in a 404 page design.

54. Improve Typography in WordPress

Have you ever wished that you can have rounded quotes, show elipses, your hyphens don’t get mixed up, well this is your lucky day because it can be done with a plugin called WP-Typography.

Web Typography Plugin for WordPress

55. Create a jQuery Carousel in WordPress

jQuery Carousel in WordPress

A great tutorial that shows you how to display your WordPress posts in a Carousel.

We hoped that you enjoyed this long and resourceful article. If you like it please retweet, and share it with your friends on Facebook.

Leave your comment

You must be logged in to post a comment.

Share IT © 2014. All rights reserved.