5 Useful Tweaks for WordPress Developers
WordPress is quickly becoming the leader in blogging and CMS technology. Over the past few years there have been more and more blogs and websites sprouting up using WordPress as their CMS system. These blogs range from small, personal sites to large corporate sites such as Yahoo, Playstation and The New York Times. That being said, it’s only natural that we seek little tweaks and tricks to get our WordPress sites to preform exactly as we’d like. Below are 5 quick and very useful little tweaks that can make a big impact on your WordPress site.
Custom “Read More” Links
This is a question I come across a lot. People want to break out of the ordinary “Read More” link, which leads to their post, and come up with something a little more creative. Well, it’s really simple if you follow these steps. The first step is to edit your posts and use a new custom field called “readmore” – the value being what you want to display instead of the standard “Read More”. Next, open up your index.php, category.php, archive.php and search.php and look for a line similar to this:
the_content("Read more");
And replace that line with this:
<?php $readmore = get_post_meta($post->ID, 'readmore', true); ?>
<?php if (!$readmore) { $readmore = 'Read More »'; } ?>
<?php the_content($readmore); ?>
Allow Only Your IP Address To Access The Admin Area
Security within WordPress is always a concern. This is a wonderful technique for anyone who is the sole administrator of their site, and doesn’t have anyone accessing the administrative area from any location other than their own. All you have to do is add your IP on line 8. You can add multiple IP Addresses if needed.
AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "Example Access Control"
AuthType Basic
<LIMIT GET>
order deny,allow
deny from all
allow from xx.xx.xx.xx
</LIMIT>
Add an Author Bio to Each Post
If you have multiple contributors to your site, this is an excellent method to distinguish who’s who. This will help your readers understand a little more about the author and in many cases help them relate as well. Some themes come equipped with this feature, but if yours doesn’t, simply add the following to your functions.php file:
function get_author_bio ($content=''){
global $post;
$post_author_name=get_the_author_meta("display_name");
$post_author_description=get_the_author_meta("description");
$html="<div class='clearfix' id='about_author'>\n";
$html.="<img width='80' height='80' class='avatar' src='http://www.gravatar.com/avatar.php?gravatar_id=".md5(get_the_author_email()). "&default=".urlencode($GLOBALS['defaultgravatar'])."&size=80&r=PG' alt='PG'/>\n";
$html.="<div class='author_text'>\n";
$html.="<h4>Author: ".$post_author_name."</h4>\n";
$html.= $post_author_description."\n";
$html.="</div>\n";
$html.="<div class='clear'></div>\n";
$content .= $html;
}
return $content;
}
add_filter('the_content', 'get_author_bio');
Customize Your Login Page
As nice as the WordPress logo is, it doesn’t hurt to put your own into the login page instead. This will give your site a more customized appearance and make your users / contributors who log in feel that they are at a more specific, rather than generic, site. Just place the following in your functions.php file and replace the image url:
function my_custom_login_logo() {
echo '<style type="text/css">
h1 a { background-image:url('.get_bloginfo('template_directory').'/images/custom-login-logo.gif) !important; }
</style>';
}
add_action('login_head', 'my_custom_login_logo');
Monitor your server in WordPress dashboard
Everyone is concerned about their site’s performance. What better solution than to monitor your server right from your dashboard? This nifty tweak will create a dashboard widget that will do just that. Add this to your functions.php file:
$logfile = ‘/home/path/logs/php-errors.log’; // Enter the server path to your logs file here
$displayErrorsLimit = 100; // The maximum number of errors to display in the widget
$errorLengthLimit = 300; // The maximum number of characters to display for each error
$fileCleared = false;
$userCanClearLog = current_user_can( ‘manage_options’ );
// Clear file?
if ( $userCanClearLog && isset( $_GET["slt-php-errors"] ) && $_GET["slt-php-errors"]==”clear” ) {
$handle = fopen( $logfile, “w” );
fclose( $handle );
$fileCleared = true;
}
// Read file
if ( file_exists( $logfile ) ) {
$errors = file( $logfile );
$errors = array_reverse( $errors );
if ( $fileCleared ) echo ‘<p><em>File cleared.</em></p>’;
if ( $errors ) {
echo ‘<p>’.count( $errors ).’ error’;
if ( $errors != 1 ) echo ’s’;
echo ‘.’;
if ( $userCanClearLog ) echo ‘ [ <b><a href="'.get_bloginfo("url").'/wp-admin/?slt-php-errors=clear" onclick="return confirm(\'Are you sure?\');">CLEAR LOG FILE</a></b> ]‘;
echo ‘</p>’;
echo ‘<div id=”slt-php-errors” style=”height:250px;overflow:scroll;padding:2px;background-color:#faf9f7;border:1px solid #ccc;”>’;
echo ‘<ol style=”padding:0;margin:0;”>’;
$i = 0;
foreach ( $errors as $error ) {
echo ‘<li style=”padding:2px 4px 6px;border-bottom:1px solid #ececec;”>’;
$errorOutput = preg_replace( ‘/\[([^\]]+)\]/’, ‘<b>[$1]</b>’, $error, 1 );
if ( strlen( $errorOutput ) > $errorLengthLimit ) {
echo substr( $errorOutput, 0, $errorLengthLimit ).’ [...]‘;
} else {
echo $errorOutput;
}
echo ‘</li>’;
$i++;
if ( $i > $displayErrorsLimit ) {
echo ‘<li style=”padding:2px;border-bottom:2px solid #ccc;”><em>More than ‘.$displayErrorsLimit.’ errors in log…</em></li>’;
break;
}
}
echo ‘</ol></div>’;
} else {
echo ‘<p>No errors currently logged.</p>’;
}
} else {
echo ‘<p><em>There was a problem reading the error log file.</em></p>’;
}
}
// Add widgets
function slt_dashboardWidgets() {
wp_add_dashboard_widget( ’slt-php-errors’, ‘PHP errors’, ’slt_PHPErrorsWidget’ );
}
add_action( ‘wp_dashboard_setup’, ’slt_dashboardWidgets’ );






[...] More: 5 Useful Tweaks for WordPress Developers : Northbound Designs [...]