Tuesday, November 30, 2010

How to Secure Your WordPress Login With One Time Password

otp-lockIf you have a little sense of security, you will know that it is totally unsafe to login to any of your private account, be it email, bank, or your WordPress site, in a public unsecured network (a.k.a free wifi). Many hackers are hanging around in the open network looking for opportunity to obtain your login credential and wreak havoc with it.

Much as we like to prevent, there will be situations (for example, when we are travelling) where we need to access our WordPress account via a public network. Luckily, we can add extra protection layer to our WordPress account so that when such situations occur, we can be sure that we are safe from hackers' clutches.

Monday, November 29, 2010

How to Test Drive New Plugins And Themes Without Making Them Live On Your Site

testdrive-mainApart from being a user-friendly CMS, what makes WordPress really great is the support for plugins and themes. With a huge library of plugins and themes, you can instantly add new features and new skins to your blog without any coding on your part.

However, if you have been blogging long enough, you will know that sometime a badly coded plugin can break the site. Worst still, it can even cause the site to crash. This goes the same for a new theme. Without any tweaking and configuration, 9 out of 10 times the theme won't look great on your site. For such cases, it is wise to test them out before making them live.

Sunday, November 28, 2010

How to Replace WordPress Cron With A Real Cron Job

wpcron-missed-scheduleWe are all too familiar with the "Missed Schedule" status, aren't we? I am sure it is very frustrating to see that all your scheduled posts went MIA.

WordPress comes with its own cron job that allows you to schedule your posts and events. However, in many situations, the WP-Cron is not working well and leads to posts missed their publication schedule and/or scheduled events not executed.

To understand why this happen, we need to know that the WP-Cron is not a real cron job. It is in fact a virtual cron that only works when a page is loaded. In short, when a page is requested on the frontend/backend, WordPress will first load WP-Cron, follow by the necessary page to display to your reader. The loaded WP-Cron will then check the database to see if there is any thing that needs to be done.

Reasons for WP-Cron to fail could be due to:

  • DNS issue in the server.

  • Plugins conflict

  • Heavy load in the server which results in WP-Cron not executed fully

  • WordPress bug

  • Using of cache plugins that prevent the WP-Cron from loading

  • And many other reasons



There are many ways to solve the WP-Cron issue, but the one that I am going to propose here is to disable the virtual WP-Cron and use a real cron job instead.

Why use a real cron job?


By using a real cron job, you can be sure that all your scheduled items are executed. For popular blogs with high traffic, using a real cron job can also reduce the server bandwidth and reduce the chances of your server crashing, especially when you are experiencing Digg/Slashdot effect.

Scheduling a real cron job


To configure a real cron job, you will need access to your cPanel or Admin panel (we will be using cPanel in this tutorial).

1. Log into your cPanel.

2. Scroll down the list of applications until you see the "cron jobs" link. Click on it.

wpcron-cpanel

3. Under the Add New Cron Job section, choose the interval that you want it to run the cron job. I have set it to run every 15minutes, but you can change it according to your liking.

wpcron-add-new-cron-job

4. In the Command field, enter the following:
[bash]wget -q -O - http://yourwebsite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1[/bash]

Replace http://yourwebsite.com with your website URL.

5. Click the "Add New Cron Job" button. You should now see a message like this:

wpcron-current-cron-job

6. Next, using a FTP program, connect to your server and download the wp-config.php file.

7. Open the wp-config.php file with a text editor and paste the following line:

[php]define('DISABLE_WP_CRON', true);[/php]

8. Save and upload (and replace) this file back to the server. This will disable WordPress internal cron job.

That's it.

To test it out, it is best to schedule a post 5 - 10 minutes after you have completed the above configuration. Wait and see if the WordPress internal cron job is fired. If yes, then congratulation, you have successfully scheduled a real cron job for WordPress. If no, go through the steps above and see if you have made any mistake. Alternatively, contact your web host and get them to configure for you.

Wednesday, November 24, 2010

How to Add Featured Images to Your Theme

WordPress first introduced the "Post Thumbnail" feature in version 2.9. This feature allows the user to set an image as the featured image for the particular post. In version 3.0, the "Post Thumbnail" feature was renamed as "Featured Image".

By default, this featured image option is not turned on. You will need to place a simple code snippet in your theme file to activate the function. Here's how you can get it to work in your current theme.

In your theme folder, open the functions.php file. Add the following code to the end of the file:

[php]add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 150, true ); [/php]

Explanation of the code


The line add_theme_support( 'post-thumbnails' ); activates the "featured image" function. You should be able to see the "Set featured image" link on the right sidebar of the post editing page or when uploading any image.

featured-image-link

The second code set_post_thumbnail_size( 150, 150, true ); determines the size of the thumbnail image. In this case, we have set it to be 150px wide by 150px tall. You can change it to suit your theme.

Displaying thumbnail images in your theme


Now that we have activated the feature, it is time to get it to display in the front end.

Open your index.php (or whatever place that you want the thumbnail image to appear). Within the loop, insert the following code:

[php]<?php
if ( has_post_thumbnail() ):
the_post_thumbnail();
endif;
?>[/php]

Note: The above code must be within the loop.

This will first check if there is any post thumbnail for the particular post. If yes, it will display the post thumbnail. If not, it will do nothing.

For more advanced uses, you can get it to display a default image when the post thumbnail is not available:

[php]<?php
if ( has_post_thumbnail() ) :
the_post_thumbnail();
else:
//url to the default image, or write your own code here
endif;
?>[/php]

That's it.

Latest Update to WordPress For Android Now Allows You to Set Post Status

I seldom blog from my Android phone, simply because the WordPress app is not good enough. Well, to be more exact, it is good enough for casual blogging and quick updating, but for managing a full fledge blog, it still can't meet the standard.

A recent update to the WordPress for Android (version 1.3.8) app adds a new "set post status" feature. You will now be able to set "Draft:, "Pending Review", "Private" or "Publish" from the app itself. While this is just another "should have been there long ago" feature, it is better late than never.

wordpress-android-set-status

Other bug fixes include:

  • Fixed crash when adding media on Dell Streak

  • Fixed crash when attempting to add a self-hosted site with an invalid blog URL

  • Fixed local db problem when upgrading from a 1.0.x or 1.1.x version

  • Updated Polish translation strings

  • Fixed crash when trying to add a second blog from a WordPress.com account or WordPress multi-user install

  • Fixed no-name blogs from showing as blank in the multi-user blog selection screen

  • Comments Loading progress bar no longer hangs



Version 1.3.8: Post Status & Bug Fixes [WordPress for Android]

Tuesday, November 23, 2010

How to Make Disqus Notify the Post Author When a New Comment Is Posted?

By default, in a multi-authors blog, you can get WordPress to notify the post author when a new comment is posted. To do this, you just have to update the “Email me whenever” field in "Settings -> Discussion".

comment-email-me

Now if you are using Disqus as your comment system, you will find that it won't notify the author when a new comment is posted. Instead, it will only notify the moderators.

To fix this, go to the Disqus-Comment-System folder in the Plugins directory. Open the disqus.php in a text editor. Scroll down to line 289 where you see the following:

[php]$comment_id = $commentdata['comment_ID'];
update_comment_meta($comment_id, 'dsq_parent_post_id', $comment->parent_post);
update_comment_meta($comment_id, 'dsq_post_id', $comment->id);[/php]

Add in the line "wp_notify_postauthor($comment_id);" so that it becomes:

[php]$comment_id = $commentdata['comment_ID'];
update_comment_meta($comment_id, 'dsq_parent_post_id', $comment->parent_post);
update_comment_meta($comment_id, 'dsq_post_id', $comment->id);
wp_notify_postauthor($comment_id);[/php]

Save, upload and replace the file back to the server.

That's it. It should notify your authors whenever there is a new comment.

Monday, November 22, 2010

How to Change the Default Height Of The Text Editor in WordPress

If you have noticed, the visible area of the text editor in WordPress is very small. Most of the time, you will have to drag the right bottom corner of the text area to enlarge it. Worst still, you have to do that every time.

Here's a quick hack to change the default height of the text area.

Open your theme's functions.php file. Copy and past the following code.

[php]add_action('admin_head', 'content_textarea_height');
function content_textarea_height() {
echo'<style type="text/css">
#content{ height:500px; }
</style>';
}[/php]

Upload the functions.php back to your server.

Note: The above code set the default height to be 500px. You can change it to the height you want.