
Are you getting the most out of your WordPress blog or website? Obviously not since you are reading this post, which by the way you shouldn’t forget to share with your friends, family, and neighbor’s cat. The beauty of WordPress lies in its massive scope of possibilities to experiment and create amazing things you’ve never dreamed of. In this post, I will share with you ten incredible tips I’ve come across and really found useful. I hope you discover something new.
-
How to add an author section in your posts
-
How to Delay RSS Feed Publication
-
How to Add Hotlink Protection to your site
-
Read More link jumps to top of post page
-
Prevent WordPress from replacing code snippets with “normal” quotes
-
Display Total Number of SQL Queries on Your Blog
-
Split posts into separate pages
You’ve just written a fabulously eloquent post called “5 Reasons Why Twitter is Better than Beer Pong.” Things are looking great on Google Analytics, and people are submitting the article to Digg and Stumbleupon in massive numbers. Problem is, no one knows who wrote this Shakespearean masterpiece. Here’s how you can add a simple author section in the bottom of your posts.
First off, make sure your author bio is completely filled out in your profile page(name, website url, biographical info). Then, proceed to your single.php file. Add the following chunk of code:
<div id="author-info">
<div id="author-image">
<a href="<?php the_author_meta('user_url'); ?>"><?php echo get_avatar( get_the_author_meta('user_email'), '80', '' ); ?></a>
</div>
<div id="author-bio">
<h4>Written by <?php the_author_link(); ?></h4>
<p><?php the_author_meta('description'); ?></p>
</div>
</div>
Here, three div’s mark out the structure of your author section. The author-info id boxes the entire content, the author-image id is where your handsome face will sit, and the author-bio id is where your author bio will show. I’ve also included some handy WordPress template tags as well.
Now that you have the HTML/PHP set up in your single.php file, it’s time to style the author section in your style.css file. Here’s the CSS I used to style my author section:
#content div#author-info {
background: #eaeaec; padding: 10px; margin: 0 0 15px 0;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
border-radius: 8px;
overflow: auto;
box-shadow: 1px 1px 12px #2D1D1D;
-moz-box-shadow: 1px 1px 12px #2D1D1D;
-webkit-box-shadow: 1px 1px 12px #2D1D1D;
}
#content div#author-info div#author-image {
float: left; margin: 0 10px 5px 0; border: 5px solid #DCDCE1;
}
Here, I used some wicked-cool CSS3 box shadow effects that probably won’t impress you. Feel free to use it on your blog.
Source: Line 25
Oftentimes, you finish a post and hit publish. The next day, you find out that something is terribly wrong. For instance, you mistakenly quoted the Pope as being the person who you played golf with last week rather than your friend Poppy. Sure, you can quickly edit the mistake but that will not do you any good for your RSS feed readers. With your credibility forever tarnished, all hope is lost. Right?
Luckily, WPEngineer has a solution for you. Simply add this code to your functions.php file:
/**
* puplish the content in the feed later
* $where ist default-var in WordPress (wp-includes/query.php)
* This function an a SQL-syntax
*/
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 = '5'; // 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');
This code will delay the publishing of your latest post to RSS feeds by 5 minutes. Of course, you can adjust that span of time by changing line 14 above.
Content thieves exist on the Internet. (NO WAY!) Don’t believe me? Then you should check your site for copycat offenders at Copyscape.com . Whereas there is no sure way to directly remove this plagiarized content, you can at least deter some thieves by using this hotlink protection method in your .htaccess file located in your root directory:
Make a backup of your .htaccess file before proceeding! Trust me! Don’t cry to me about it in the comments section below if you forget.
#Begin Hotlink Protection
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?yoursite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteCond %{HTTP_REFERER} !msn\. [NC]
RewriteCond %{HTTP_REFERER} !yahoo\. [NC]
RewriteCond %{HTTP_REFERER} !^http://www.feedburner.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://feeds.feedburner.com/yoursite$ [NC]
RewriteRule .*\.(jpe?g|gif|bmp|png|jpg)$ /images/nohotlink.jpe [L]
#End Hotlink Protection
I highlighted the three lines you need to change above. So far, this method has worked brilliantly for me, and also not so brilliantly. Before, I did not include the feedburner code, and thus all of my images in my RSS Feed began displaying my hotlink image, which by the way looks like this:
Intimidating? I thought so. Please use this with caution though, especially since you are dealing with the .htaccess file.
I no longer enable hotlink protection on this site due to its inconsistency and tendency to replace images on this site with the hotlink image. If you have a better method, please feel free to share them in the comments section below.
Source: David Airey
By default, the <!--more--> tag will send readers to the location of the tag on the post. Alternatively, you can have the more link send readers to the top of the post page instead. Simply, add this code to your functions.php file:
function remove_more_jump_link($link) {
$offset = strpos($link, '#more-');
if ($offset) {
$end = strpos($link, '"',$offset);
}
if ($end) {
$link = substr_replace($link, '', $offset, $end-$offset);
}
return $link;
}
add_filter('the_content_more_link', 'remove_more_jump_link');
Source: WordPress Codex
Imagine my angst when I sat in front of my pathetic Gateway laptop wondering why the code I used from a site doesn’t seem to work when I paste it into my files? I obviously made no errors since I’m a coding god, so it must be the Internet’s fault right?
By default, WordPress replaces quotes in code snippets you copy and paste from somewhere and converts them to “curly” quotes instead of the “normal” quotes. To solve this, paste the following line of code into your functions.php file:
[php]<?php remove_filter(‘the_content’, ‘wptexturize’); ?>[/php]
Source: WPRecipes
Queries are evil. They slow down your site as you begin to accumulate more, which can negatively effect the user experience. In fact, Google agrees too. The first step to lowering queries is to know how many you actually have. Simply paste the following line of code somewhere on your site. I prefer going after the footer.php file.
<?php if (is_user_logged_in()) { ?>
<?php echo get_num_queries(); ?> queries in <?php timer_stop(1); ?> seconds.
<?php } ?>
If you want this to be publicly shown, simply remove lines 1 and 3.
This tip is quite handy when you are dealing with lengthy posts, especially those that contain a lot of pictures. To reduce the possibility of people jumping ship as they wait for your “1,000,000,000,000 Pictures of Funny Cats” epic post to load, add this tag to any section of your article you want to split into a separate page:
Pages: 1 2
Pingback: Rough Ride Creations Blog » Essential Wordpress Installation, Optimization & Security Resources