Tips for Optimizing WordPress Blog


Do you have a WordPress blog that is self-hosted?  Consider using these tips to optimize it?

English: The logo of the blogging software Wor...

Image via Wikipedia

The beauty of WordPress is in how easy it is to adapt for different tasks. One can extend it with just a couple of lines of code. In this post, we’ll review 10 shortcode snippets that will tweak and optimize your WordPress theme. You can add all of these code snippets to the functions.php file in your WordPress theme.

Limit The Excerpt’s Word Count

One thing that can go wrong in WordPress magazine themes is when users include too many words before the more tag. Sure, they could handcraft the excerpt in the dedicated field, but on a website that has hundreds of posts and on which the text above the more tag has always been used as the excerpt, going back to create excerpts for all of those posts by hand would be cumbersome. In this case, we can limit the number of words shown in the excerpt by using this code:

1 add_filter('excerpt_length', 'ilc_excerpt_length');
2 function ilc_excerpt_length( $length ){
3     return 10;
4 }

Here, we’re using a WordPress filter hook, which is a function that parses and (usually) modifies data before it gets stored in the database or displayed on a page. In this case, we’re setting the number of words shown in the excerpt to 10.

Add A Favicon Using A WordPress Hook

Hooks allow us to insert custom code without touching the template. This gives us a lot of flexibility, because now, whenever we need to change something, we only have to change the function that’s plugged into a certain hook. For example, you can add a favicon to your website without touching the header.php file, just by plugging a function into the wp_head hook:

1 add_action( 'wp_head', 'ilc_favicon');
2 function ilc_favicon(){
3     echo "<link rel='shortcut icon' href='" . get_stylesheet_directory_uri() . "/favicon.ico' />" . "\n";
4 }

The favicon.ico file should be located at the root of your theme. We’re now using an action hook, which is a function that is triggered at specific points during an execution by WordPress’ core. In this case, the hook triggers any function that’s attached to it when a page is launched in the browser. But other hooks can be triggered when saving a post, registering a user and so on. Some themes even have their own action hooks, which, like WordPress’ core action hooks, can be used to launch functions at specific points of an execution.

Redirect WordPress Feeds To FeedBurner

It’s great that WordPress offers feeds out of the box. But if you want statistics about your subscribers, you’ll have to use FeedBurner or a similar service. To redirect your feed to one of these, use the following snippet. Thus, if you try to go to http://www.smashingmagazine.com/feed (http://www.smashingmagazine.com/feed), you’ll be redirected to FeedBurner’s feeds for Smashing Magazine (http://feeds.feedburner.com/smashingmagazine).

1 add_action('template_redirect', 'ilc_rss_redirect');
2 function ilc_rss_redirect() {
3     if ( is_feed() && !preg_match('/feedburner|feedvalidator/i', $_SERVER['HTTP_USER_AGENT'])){
4         header('Location: http://feeds.feedburner.com/smashingmagazine');
5         header('HTTP/1.1 302 Temporary Redirect');
6     }
7 }

Replace http://feeds.feedburner.com/smashingmagazine with the URL for your own feed from FeedBurner.

Go to the source to see additional tips for optimizing your self-hosted WordPress blog.  Are there other things besides these tips that you have utilized?

Enhanced by Zemanta

 

Advertisements

About brvanlanen

Just a thirty-something guy currently hanging it up in the greater Green Bay area. My post-high school educational background is mainly in the Information Technology field. Specifically I have an A.A.S. in Computer Network Systems and a B.S. in Information Systems Security, both from ITT Technical Institute, in addition to A and MCDST certifications. In my free time I enjoy spending time with my family, cooking and sports. My Christian faith is also important to me as a Missouri-Synod Lutheran and all my children attend a Lutheran grade school. When it comes to political leanings I am a conservative first and foremost which you will discover rather quickly. As for sports I am a huge fan of the Green Bay Packers.

Posted on December 11, 2011, in Blogging, Tech Tips, WordPress and tagged , , , , , , , . Bookmark the permalink. 2 Comments.

%d bloggers like this: