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.

  • Share/Bookmark
Tags: Site Optimization Tips, Web development, web masters, Wordpress

Similar posts that you may like

Subscribe to Tips and Tricks HQ to stay informed

twitter_icon

13 Comments (and 2 trackbacks)

  • #1 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 My ComLuv Profile

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

    Wonderful tips ..

    thank you
    regards
    john

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

    Thanks for sharing. I really like this blog!

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

    The tips are very helpful for me. Thankyou.

  • #5 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 My ComLuv Profile

  • #6 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.

  • #7 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??

  • #8 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.

  • #9 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 My ComLuv Profile

  • #10 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 My ComLuv Profile

  • #11 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 My ComLuv Profile

  • #12 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”.

  • #13 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 My ComLuv Profile

CommentLuv Enabled

Featured & Popular Articles

Tips and Tricks Hot Items

wordpress_estore_icon
wordpress membership plugin
WordPress PDF Stamper Plugin
WordPress Affiliate Link Manager Plugin
wordpress_affiliate_plugin_icon