2 Simple WordPress Blog Optimization Tips and Tricks

Categories: Site Optimization Tips

I have been pretty busy with the WordPress plugin development lately, so didn’t get a chance to write any posts for a few weeks. I think it’s about time I share a simple but effective website performance improvement trick with the readers of this site that I have been using on all my sites. If you haven’t read the WordPress site optimization tips and tricks already then you should read that first.

This trick involves changing some of the dynamic wordpress queries to static ones which in turn reduces the number of database queries and improves site performance. This does require a little bit of PHP knowledge but it’s really basic stuff.

In your WordPress theme’s header and footer you will see many statements similar to the following:

bloginfo(‘home’)

This queries WordPress for the home URL of your blog (eg. http://www.your-site.com). Now, how often do you think your home URL is going to change? Most likely never! So why not replace it with the static information which is “http://www.your-site.com” and make one less database query?

Saving one database query may not sound very convincing but you probably have many statements like the following that can also be replaced:

bloginfo(‘html_type’)
bloginfo(‘charset’)
bloginfo(‘name’)
bloginfo(‘version’)
bloginfo(‘stylesheet_url’)
bloginfo(‘rss2_url’)
bloginfo(‘template_directory’)
bloginfo(‘home’)

Now multiply that by every page load per visitor. This in turn can save thousands of extra database queries depending on the number of traffic you get and improve your site’s performance a little. When you are on a shared hosting plan (which most of you will be when you first start out) it helps increase your page load time and also takes a little bit of pressure off the CPU.

How to go about doing this?

It’s just a matter of finding what each one of these queries retrieve from the database then replace that query string with the static info. I normally “echo” the output of all these queries and then take that output and replace the query with it. You can probably put the following in one of your theme’s file and find what the output of each one of these queries are then simply search and replace them:

echo bloginfo(‘html_type’);
echo bloginfo(‘charset’);
echo bloginfo(‘name’);
echo bloginfo(‘version’);
echo bloginfo(‘stylesheet_url’);
echo bloginfo(‘rss2_url’);
echo bloginfo(‘template_directory’);
echo bloginfo(‘home’);

This link has a few examples and can be useful when doing this.

Move Javascript at Bottom of the Page

Your site can run very slow or stall if another site that you call Javascript from is down. Moving the Javascript to the bottom of the page allows your visitor to still see your page content even though the javascript at the bottom is not loading for some unknown reason.

Moving the javascript to the bottom of the page is a common tip but I sometimes get asked the following question:

“How do I move Javascript to the bottom of the page exactly?”

So I am going to quickly cover this here. There may be exceptions where you specifically want to load the javascript in the header but generally it should be moved to the bottom of the page (footer of your theme). The HTML code to load a javascript looks similar to the following:

<script type=”text/javascript” src=”http://www.your-site.com/wp-content/themes/theme-name/scripts/some-script-file.js”></script>

So you can open your theme’s “header.php” and search for the word “javascript”. Once you find a line similar to the one above, cut that full statement (opening tag to end tag) and paste it in the “footer.php” file.

Articles you may also like:

  1. WordPress Optimization Tips and Tricks for Better Performance and Speed
  2. WordPress Affiliate Platform Plugin – Simple Affiliate Program for WordPress Blog/Site
  3. Essential WordPress Security Tips – Is Your Blog Protected?
  4. How to Add Far Future Expires Headers to Your WordPress Site
  5. WordPress Plugin for Simple Google Adsense Insertion/Integration
Tags: , , ,

Subscribe to Tips and Tricks HQ to stay informed

twitter_icon

22 Responses.

  • #1 by Colorado SEO Consultants on July 21, 2011 - 5:32 am

    Brilliant yet simple tips! I’m surprised there isn’t a plug in in WordPress to find and replace all these query items for you. I can imagine it would speed up a popular blog very much.

  • #2 by Mark Sim on June 13, 2011 - 11:25 pm

    You should try not to put the JavaScript code at the bottom of a page. It will take some time for the code to load and your website may not look completed when a visitor is looking at it. Thank for the WordPress blog optimization tips, though.

  • #3 by aurora chiropractic on June 9, 2011 - 2:27 pm

    This improved my blog layout very much, thanks for those 2 tips

  • #4 by smhcarhire on May 16, 2011 - 8:16 am

    Nice tips and easy to implement..thanks for sharing

  • #5 by sam on February 21, 2011 - 5:09 pm

    these tips are really good and quick to implement, thanks for that!

  • #6 by Matt on January 10, 2011 - 1:30 pm

    This is great material and has helped me in several ways. I have tried to find this information elsewhere, but other sites just confuse things and make them harder than they actually are. Thanks for the help!

  • #7 by John Gamings on January 3, 2011 - 10:51 am

    Nice tips. Unfortunately, this can make your theme nonportable, which can be a real hassle. Still interesting though

  • #8 by tanhak on May 22, 2010 - 2:19 am

    i have so many problems in my website .. getting so many times in loading

    can any one friendly solve it .. i send it header.php and footer.php .. can he sets to me in a right way .. please ..
    .-= tanhak´s last blog ..Private jobs, Public Sector Organization Job Opportunities =-.

  • #9 by admin on April 10, 2010 - 3:33 am

    If it’s a plugin then it’s best to request the plugin developer to do it otherwise the changes you make will get lost during an upgrade of that plugin.

    But if you want to change the code of the plugin then look for a line similar to this:

    add_action('wp_head', 'function_name....');

    You will see in the “function_name….” it has included those scripts. Simply move them to the footer using another action called “wp_footer”.

  • #10 by Amber on April 10, 2010 - 2:40 am

    I was able to move the jscript to the bottom of my theme file, but Yslow tells me two e-commerce plugin files still have jscript at the top. Where should the script be moved when it’s in one little plugin file like that?
    .-= Amber´s last blog ..Bloggin’ Plans =-.

  • #11 by Amber on April 10, 2010 - 2:08 am

    If yslow is telling me that jscript from a plugin is in the page header, (for example, “http://www.nsvintage.com/main/wp-content/plugins/wp-e-commerce/share-this.php”), to where should that jscript be moved?
    .-= Amber´s last blog ..Bloggin’ Plans =-.

  • #12 by Jasmin on March 10, 2010 - 7:37 am

    Thanks for the grat work. After searching nearly 1 hour I found what I was looking for.)
    .-= Jasmin´s last blog ..AdSense Background Pictures =-.

  • #13 by 2base tl on January 7, 2010 - 12:22 pm

    I found your blog on google and read a few of your other posts. I just added you to my Google News Reader. Keep up the good work Look forward to reading more from you in the future.

  • #14 by Charles on January 4, 2010 - 11:17 am

    I’ve always wondered if WP super cache interfered with Adsense on a page. If the whole page is made static then the ads won’t change??

  • #15 by admin on November 22, 2009 - 8:01 pm

    WP Super Cache is really good and has it’s usage but remember there is no one solution that fits everyone’s need. For example, I don’t use wp super cache myself because of other complications.

  • #16 by Bob on November 22, 2009 - 9:01 am

    I wouldn’t recommend doing this! This makes your theme non-portable. Also, if you relocation your blog, e.g. directory change, change to domain (www.mydomain.com to blog.mydomain.com, etc.), you’ll be in trouble.

    If you’re worried about performance, just enable wp-cache or wp-super-cache.

    Don’t tweak your theme, stay generic
    .-= Bob´s last blog ..Comment Rating Widget Faq =-.

  • #17 by Jane on November 7, 2009 - 10:18 am

    The tips are very helpful for me. Thankyou.

  • #18 by Caroline on November 7, 2009 - 10:16 am

    Thanks for sharing. I really like this blog!

  • #19 by John Michael on October 14, 2009 - 6:30 pm

    Wonderful tips ..

    thank you
    regards
    john

  • #20 by Kenny Meyer on September 23, 2009 - 10:02 am

    Thanks for sharing this… I like tweaking my wordpress-blog and this is very helpful in doing so.
    .-= Kenny Meyer´s last blog ..Upload images to flickr.com per commandline =-.

Featured & Popular Articles

Tips and Tricks Hot Items

wordpress estore plugin
wordpress membership plugin
WordPress PDF Stamper Plugin
WordPress Lightbox Ultimate Plugin
WordPress Affiliate Link Manager Plugin
wordpress affiliate plugin