Cufón for Thematic with no plugins – improved

Since I wrote the original ‘Cufon for Thematic with no plugins‘ post, I’ve learnt how to use script queueing, rather than hard-coded links. Here’s the official WP page about script queueing: http://codex.wordpress.org/Function_Reference/wp_enqueue_script if you want to find out more.

Here’s the improved version of that post, also featuring a little function to convert the doctype into XHTML Strict, which Cufon needs in order to observe CSS line-height declarations:

// Enqueue Cufon and Font JS files
if ( !is_admin() ) { // instruction to only load if it is not the admin area
// register scripts
wp_register_script('cufon-yui',
get_bloginfo('stylesheet_directory') . '/js/cufon-yui.js',
array('jquery'),
false,
false
);
wp_register_script('font-yourfont',
get_bloginfo('stylesheet_directory') . '/js/YourFont.font.js',
array('jquery', 'cufon-yui'),
false,
false
);
// enqueue scripts
wp_enqueue_script('cufon-yui');
wp_enqueue_script('font-yourfont');
}

// Cufon needs strict doctype for line-height
function childtheme_create_doctype($content) {
$content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
$content .= "\n";
$content .= '<html xmlns="http://www.w3.org/1999/xhtml"';
return $content;
}
add_filter('thematic_create_doctype', 'childtheme_create_doctype');

// Add extra scripts to head
function childtheme_head() { ?>
<!-- Cufon -->
<script type="text/javascript">
Cufon.replace('h1, h2', { fontFamily: 'YourFont' });
</script>
<?php }
add_action('wp_head', 'childtheme_head');

// Load Child Theme js file, Google Analytics
function load_childtheme_js() {?>
<script type="text/javascript"> Cufon.now(); </script>
<?php }
add_action('thematic_after','load_childtheme_js');

Any comments or corrections, please shout in the comments!

2 Comments

  1. Hi Dave,
    In case it’s of use to you or others – Cufon does require a strict doctype, but it doesn’t have to be XHTML Strict. A simple (“HTML5”) doctype also works fine:

    <!doctype html>

Comments are closed.

Secured By miniOrange