Cufon.replace Even When Text Is Loaded by AJAX or jQuery

Recently I was confronted with a challenge: how to get the text of a heading that was being inserted with jquery+livequery to be replaced with Cufon.

The dilemma: Cufon couldn’t replace the text and it remained the plain, default typeface.

Luckily for me the last post this forum thread reported a way to fix it. Their solution was specific to the task they were trying to accomplish but it was simple to figure out how to re write to solve my problem.

If you are using Cufon already you’ll be familiar with this:

[php]Cufon.replace(‘h2.title’, { fontFamily: ‘greatfont’ });[/php]

If you’re familiar with jQuery you’ll be familiar with this, too:

[php]$("h2.title").livequery(function() {
$(this).text($("#breadcrumbs li:last-child").text());})[/php]

What I had to do was combine each into one function as a separate call from my other Cufon.replace code.
[php]$("h2.title").livequery(function() {
$(this).text($("#breadcrumbs li:last-child").text());
Cufon.replace(‘h2.title’, { fontFamily: ‘greatfont’ });
})[/php]

As added insurance I placed this right before the closing body tag:
[js]<script type="text/javascript">Cufon.now(); </script> [/js]

One of the Pains in My Ass

Just one.That’s all you can handle,right?

Plugin authors have had a pain in their collective asses,too because they have to remember to do this: wp_enqueue_script(‘jquery’); when using jquery in their plugins if it’s going to be used in the site admin section (the dashboard) because a lot of jquery is used there. But not all of the plugins I was using at the time of this writing did this. Following one plugin author’s instructions I tried to edit a plugin file but got a syntax error. So I said fooey and just edited it to use the jquery version in /wp-includes/js/jquery.

Now I can use Custom Fonts and upload images. Awesome.