Help Stop SOPA/PIPA

WordPress webdesign and development in Houston Texas

Add a Re-Tweet Button in an Iframe for Faster Page Loads

One of the topics discussed in my WordCamp Houston Presentation, Optimizing For Performance, was putting social media share buttons in an iframe to improve page rendering. I thought it would be helpful to describe in more detail how to accomplish this.


Since Facebook already does a pretty good job of putting their widget code in an iframe we will use the TweetMeMe Re-Tweet button for this example. If you were to just put the code directly in an iframe it wouldn’t help much because Javascript embedded in an iframe will block the rest of the page from loading until it was complete.

To accomplish our goal of progressive page rendering we will need to start with a div placeholder for our iframe code and write a short Javascript function to add the iframe code to our placeholder div once the page has completely loaded. This is the same method Fredrick Townes, creator of the W3-Total Cache plugin and CTO of Mashable.com, uses to place the buttons on Mashable.

First we need to add our div placeholder to our template files where we want the Tweetmeme button to appear. In this case we will use div id=”tm_box” then close the div.

Next we will need to build our iframe src variable.

1. Start with the button.js url that Tweetmeme provides in their embed code:
http://api.tweetmeme.com/button.js
2. Add ?url= followed by the page url (for now we will add URL as a placeholder because we will want the url to be whatever page the button is placed on).
3. Add &style= followed by what button style you will want to use. Either normal or compact.
4. Add &source= followed by your Twitter username.
5. Add &service= followed by a URL shortening service for ease of use we will use the bit.ly service see the Tweetmeme api reference on how to add other services.

Your completed src variable will look something like this:
http://api.tweetmeme.com/button.js?url=URL&style=normal&source=Chris_Olbekson&service=bit.ly

Now we will set the width and height attributes:

For the normal style button: width="50" height="61"
For the compact style button width="90" height="20"

Now that we have all our variable our iframe code will look something like this:

<iframe src="http://api.tweetmeme.com/button.js?url=URL&style=normal&source=Chris_Olbekson&service=bit.ly" scrolling="no" frameborder="0" width="50" height="61" ></iframe>

Now to convert your iframe code from html to JavaScript you can use this simple online HTML to JavaScript Converter

Next we need a JavaScript function get the current page url. We will use the escape() function just like TweetMeme uses in its button.js and we will add window.onload = tweetMemeButton which will fire the code after the page is completely loaded.

Here is our completed JavaScript which we can save as an external file and call it in header.php or footer.php (It won’t matter where we call it because it won’t fire till the page is loaded).

function tweetMemeButton() {
	if (document.getElementById("tm_box")) {
		var iframeCode= "";
iframeCode += "<iframe src="http://api.tweetmeme.com/button.js?url=" + escape(document.URL) + "&style=normal&source=chris_olbekson &service=bit.ly" scrolling="no" frameborder="0" width="50" height="61" >";

		document.getElementById("tm_box").innerHTML = iframeCode;
	}
}

window.onload = tweetMemeButton;

This code is used to add the TweetMeMe Re-Tweet button at the end of this post.

**Update: 08/12/2020
Twitter just announced the release of their new tweet button. I will be evaluating the performance over the next few days.

Optimizing WordPress for Performance WordCamp Houston

WordCamp Houston

I will be speaking at Houston’s first WordCamp, a one day camp dedicated to serving beginner to advanced, businesses to bloggers, and everyone in between.

My topic will be “Optimizing for Performance” – How to make your WordPress Blog Faster and Scalable. The discussion will include tips for installing and configuring the W3 Total Cache plugin and how to take advantage of APC, X-Cache, or eAccelerator opcode caching, using efficient CSS selectors and theme files, and how to maximize your MySql database for performance.

WordPress 3.0 New Features

WordPress Version 3.0  is set to be released in the next week or so and contains some exciting new enhancements and improvements over previous versions.

I have been working with the beta and release candidate versions over the past few weeks to develop a client project. I had to make the decision early on to use WordPress 3. My choice was to develop it with the older version and be safe or take a chance with the new version and the possibilities of things going wrong along the way.

Luckily everything turned out great and I only encountered a few minor issues along the way.

I made it a point to keep up with the nightly builds and back up the database daily before every update. I benefited by becoming an expert in custom post types and taxonomies and I want to share some of this knowledge and will be writing a series of articles and tutorials on everything from the new built in menu system, custom post types, custom taxonomies, customizing the login page and admin interface and much more.

This post will serve as a starting point and will list many of the enhancements, fixes, and new features in Version 3.0.

Will the new version break my theme or cause any conflicts?
No everything will still work when you install WordPress 3.0.

Can I start using the new features right away?
Most of the new features including menus and custom post types require theme support via functions.php.

User Enhancements

  • New default theme 2010
  • New menu management user interface
  • Custom backgrounds for themes
  • Custom header images for themes
  • New admin color scheme
  • Enhanced media upload interface
  • Ability to add theme css classes to post editor
  • Category to tag and tag to category converter
  • More secure install process (removes default admin username

Developer, Theme and Plugin Enhancements

  • Custom post types with built in UI
  • Custom taxonomies for any post type with built in UI
  • New template files: front-page.php, single-{post_type}.php, author-{nickname or ID}.php, taxonomy.php, taxonomy-{taxonomy}.php, taxonomy-{taxonomy-term}.php
  • New template tags and functions see Codex Version 3.0
  • JQuery updated to 1.4.2 and JQuery UI to 1.7.2
  • add_theme_support function call to include the new features
  • Built in multi site built in via: WP_ALLOW_MULTISITE in config-php
  • wp-ajax.php file to use for front end and plugin ajax support

As a developer and web designer, I am very happy with WordPress 3.0. It moves it more to being a full fledged content management system than it was before and opens up more options for the theme developer, plugin developer, web designer and end user.

Global Quality Imports

Coming Soon Landing Page Options

Help “Crowd Source” the coming soon landing page design for a Southern California start up construction management company. The chosen design will also be incorporated into the final site.