typekit-logo

TypeKit Code Snippet

Posted

Assuming you don’t want to use the TypeKit plugin, here’s how to enqueue the scripts directly from your theme:

/**
 * TypeKit Fonts
 *
 * @since Theme 1.0
 */
function theme_typekit() {
    wp_enqueue_script( 'theme_typekit', '//use.typekit.net/xxxxxxx.js');
}
add_action( 'wp_enqueue_scripts', 'theme_typekit' );

function theme_typekit_inline() {
  if ( wp_script_is( 'theme_typekit', 'done' ) ) { ?>
  	<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
<?php }
}
add_action( 'wp_head', 'theme_typekit_inline' );

Translatable Javascript Strings

Posted

I’ve been working on a plugin that needs to update the text of an object via javascript when an element is clicked. Like the rest of my plugin, those strings in the javascript need to be translatable. Thankfully WordPress makes this easy to do.

Original

Let’s say this is the script you are enqueuing:

function prefix_enqueue_custom_script(){
	wp_register_script( 'prefix_custom_script', plugin_dir_url( __FILE__ ) .'js/custom-script.js', array( 'jquery' ) );
        wp_enqueue_script( 'prefix_custom_script' );
}

Translatable

In this custom script there are two strings that should be translatable: “upload” and “remove”. To make this happen we’ll use the wp_localize_script function, which gets hooked onto the script handle:

function prefix_enqueue_custom_script(){
	wp_register_script( 'prefix_custom_script', plugin_dir_url( __FILE__ ) .'js/custom-script.js', array( 'jquery' ) );
        wp_enqueue_script( 'prefix_custom_script' );
        wp_localize_script( 'prefix_custom_script', 'prefix_object_name', array(
		'upload' => __( 'upload', 'textdomain' ),
		'remove' => __( 'remove', 'textdomain' )
	) );
}

Using the Strings

Now in my javascript, instead of simply using the text “upload” and “remove” I’ll use the variables prefix_object_name.upload and prefix_object_name.remove.

Options Framework Sidebar

Posted

The latest version of the Options Framework has a new hook to display content below the options panel. This feature was added thanks to @Satrya, who posted a neat screenshot on GitHub and requested it.

The hook can be used to display any content below the options panel, but one cool use is to add a sidebar with additional information about the theme. Here’s an example:

I added a demo theme of this to the Options Theme Kit if you’re interested to see exactly how it works.

Here’s a slightly simpler example:

add_action('optionsframework_after','exampletheme_options_after', 100);

function exampletheme_options_after() { ?>
    <p>Content after the options panel!</p>
<?php }
infinity-banner

Infinite Scroll in WordPress

Posted

Infinite scroll has become a standard feature in many web applications. Twitter and Facebook are the ones I use every day, but it’s also in a ton of Tumblr themes and Cargo Collective sites.

I feel WordPress themes has been slow to adopt infinite scroll- but after adding it to my site over the weekend I understand some of the complications.

Unlike Tumblr or Cargo Collective, WordPress (.org) users can use plugins to add all sorts of javascript to posts. On my site Syntax Highlighting is the main culprit (which I use to display code snippets), but many others have social buttons or lightboxed images.

When infinite scroll pulls in additional posts via ajax, it doesn’t load the javascript code from the header or footer of the post that might be needed to display js content (e.g. social buttons, formatted code, etc) properly. That puts theme authors in a bind. Infinite scroll may be a better end user experience, but it’s going to lead to more support requests during theme set up.

However, if you don’t use much javascript in your post content, or if you display excerpts on your index pages rather than full posts, I’d suggest trying it out.

The Infinite Scroll plugin recently had a complete rewrite, and I can now recommend using it again. If you use the plugin you should be able to set up infinite scroll for your theme in just a couple minutes.

I’ll also posted a tutorial about how to add Infinite Scroll to a theme without a plugin.

Useful Links:

Image Credit: Infinity Pool

WP Engine Hosting Review

Posted

I’ve hosted most of my sites with BlueHost the last six years, but I recently migrated this one over to WP Engine. I was mainly curious to see what the impact on page speed would be. As WP Theming has grown in traffic so have load times– despite good caching, gzipped files, minified scripts and css, and sprited images.

Page Speed

The home page of the site had a page speed score of 96% before the migration and roughly 81% after. No theme code changed and the only plugin removal was W3 Total Cache. However, load times improved significantly (as measured by Google):

This Google Page Speed graph shows that page speeds were 1.47 seconds faster after the migration, which is 25% improvement.

You’ll notice average page speed is 1.47 seconds faster, which is a significant 25% improvement. I’d venture to guess the numbers might be even more impressive for someone who had not already worked to optimize load times.
Read more

TypeKit on Body Text

Posted

There are a number of solutions for rendering “non-standard” web fonts on your site.  I was familiar with ones like SIFR and Cufon where it’s recommend to be used only on headers or certain spots of the website.  I e-mailed TypeKit to see if it worked the same way, and got this reply from Mandy Brown:

“There’s no file size or speed issue with using Typekit for body text (as there would be with, say, using SIFR or Cufon). That said, you should make sure to use a font that works well at small sizes and renders acceptably cross-browser. Be sure to take a look at the browser screenshots before deciding on a font.”

Oddly, Google failed me on this question, so I thought I’d post it here for anyone else who was curious.

demand

What’s Next for WP Theming

Posted

I’ve been working as freelance web developer for the last couple years working almost primarily with WordPress. I’ve enjoyed every minute of it, but I was recently offered the opportunity to work full time with Demand Media.

Demand Media runs eHow.com, Trails.com, Livestrong.com (among others) and social widgets that are viewed on millions of pages per day. It’s a really exciting company and position. Couldn’t pass it up. I start today, which also just happens to be my 29th Birthday.
Read more

Browser Refresh Button

How to Refresh Your Browser

Posted

When you view a website, your browser will usually save a copy of all the files onto your hard drive. This is called a browser cache. It does this so the page loads quicker the next time you view it and everything doesn’t need to be downloaded again.

Browsers will generally be able to detect if the website has been updated and get a copy of the new files, but sometimes it fails. This is especially true if your web designer has been changing background images or xml files. To see those changes, you will need to refresh your browser.

Here’s a short video screencast explaining how to refresh the browser in Firefox, Safari, Google Chrome, and Internet Explorer 6.
Read more