WordPress & In-Line jQuery: $ Is Not A Function

I ran into a problem I had not come across in all my years using jQuery and using WordPress.  I had embedded some JavaScript code in-line (not in an external .JS file), as such:

Pretty simple code that toggles visibility between two DIVs when one of two buttons is pressed.  I uploaded the files and tested it out.  Lo and behold, it didn’t work!  My Web Developer toolbar add-in for FireFox reports: “$ is not a function”. What could I have messed up in my JavaScript? Nothing, as it turns out.

It seems that the “$” dollar sign is reserved in WordPress for use by Prototype.  The solution?  Refer to jQuery instead of the dollar sign.  In my example, the code becomes:

Hope this helps some of you out there.

2012: The Year You Get Your Mobile On

It’s time to go mobile.  If you’ve been operating a website a while, good for you, you’re still ahead of the curve compared to many of your competitors.  But if you happen to track the statistics of this website, you might have noticed a funny thing.  People are still browsing with Internet Explorer and Firefox, but now they’re also coming to your website from Mobile Safari, Android, iPad and a whole host of other mobile devices.

And the thing is, it’s happening everywhere.  See for yourself!  Here’s a look at mobile device usage for four websites we operate, each with a different size and scope, target demographic, monthly traffic level, even geographic location.

Mobile device usage statistics for 4 websites

Mobile device usage is picking up across the board.  Some later than others, but it’s undeniable: people are using the web from their phones.  Launching a mobile-optimized website is a great way to take advantage of this opportunity.

We package up the most important details about your organization, present them in a format optimized for the reduced screen sizes (and download speeds), that is attractive, easy to use, and themed to match your full website.  We can even integrate with core phone features like Maps and Phone to provide driving directions or initiate a phone call or text message, directly from the mobile site.

We can usually integrate with your existing Content Management System.  If you don’t have one now, we can install a CMS for the mobile site to make maintenance and updates a breeze.

If you’re interested in launching a mobile website, give us a call at (405) 633-1810 or contact us online.

Here’s a look at some of our clients’ mobile sites:

Regional Food Bank of Oklahoma | Mobile Website

Regional Food Bank – we mobilized all the core features of the Food Bank’s website including online donations, volunteer sign up form, partner agency search, upcoming events, contact information, program information and more. Partner agency search can use your phone’s GPS positioning technology to find the agency nearest you!  Visit www.regionalfoodbank.org from your mobile device.

ionOKLAHOMA Custom Mobile Website

ionOKLAHOMA – ionOK has attracted huge online audiences from their local event photo galleries and online video diaries, and their weekly editorial and bi-monthly digital magazine.  We created mobile photo galleries, video player, story spinner and editorial archives.  Visit www.ionok.com from your mobile device.

Mobile Website | Oklahoma Bankers Association

Oklahoma Bankers Association – the OBA needed a mobile version of their website to serve their mobile audiences, and of equal importance, to serve as an educational tool and show piece for their members banks.  We created a clean, elegant mobile website that showcases their news articles, Banks On The Web directory and other key content areas.  Mobile website launching soon.

Va Bene Berarducci's Caffe | Mobile Website

Va Bene Caffe – We developed a mobile version of Va Bene’s website in response to a sudden, tremendous growth of mobile users in Duluth.  More than 25% of all visits to the restaurant’s website are from mobile devices. When we decided to launch a mobile version of the site, we included what we knew people would be looking for: hours, location, phone number and menus.  We also included contact and catering information.  Visit www.vabenecaffe.com/mobile/ from your mobile device.

Nivo Slider and Image Thumbnails Positioning Solved!

I’ve always custom built JavaScript-powered sliders for my clients.  When I stumbled upon Nivo Slider, I was pretty impressed with its features, fade transitions and ease of integration.  It seemed like the perfect fit to display photo galleries on the new website for Oklahoma City photographers, Brock’s Photography.

But, when I got down to the nitty-gritty of implementing image thumbnails, I found an incredible lack of support for integrating this great feature.

So, here’s what I did to get the image thumbnails to display properly in a Nivo Slider powered gallery.

The first step is to specify an image thumbnail location in the HTML through the use of the rel=”“ attribute.  This indicates to Nivo the location of the thumbnail image file.  You’ll see I’ve placed my Nivo Slider elements within a container DIV, #gallery.  This will become important later because we’ll resize this container.


Even though Nivo knows where the thumbnails are, and sets their objects up in the slider, they are not visible.  Let’s modify the CSS to activate them.

.nivo-controlNav a {
display:inline; /* Display the thumbnail link element */
}

#slider .nivo-controlNav img {
display:inline; /* Un-hide the thumbnail image element */
position:relative;
margin: 10px 10px 0 0; /* Provide some white space around the thumbs */
}

Great!  Now we’ve got image thumbnails.  But, the positioning is off. Let’s adjust so the thumbnails appear below the gallery image:

#slider .nivo-controlNav {
position: absolute;
top: 600px; /* 600px is the height of our gallery image */
}

That solves positioning.  But, what’s even worse, is that when we have so many images that thumbnails wrap to a second row and beyond, the thumbnails overlay on top of the rest of our content beneath the slider.  Ouch!  I could set the height or positioning in CSS, but I’ve written a custom plugin allowing my client to manage the gallery images herself, so I can’t hard code positioning since I don’t know if we’re dealing with one row of thumbnails or six.  Double ouch!

So, I wrote a JavaScript function to calculate the appropriate height.  This grabs the height of the slider, the height of the thumbnails container, and then resizes the container DIV (#gallery) appropriately so that any content below our slider gets bumped down the page.

function sizeThumbs(){
    var thumb_height = $(".nivo-controlNav").height();
    var gal_height = $("#slider").height();
    var this_height = (thumb_height+gal_height); /* Calculate total height */
    $("#gallery").height( this_height );
}

We need to call this function after the slider loads.  Luckily, Nivo Slider makes this incredibly easy.  We just add an additional parameter to the $().nivoSlider() function:

$('#slider').nivoSlider({
effect: 'fade',
controlNav:true, /* Display the control navigation */
controlNavThumbs:true, /* Display thumbnails */
controlNavThumbsFromRel:true, /* Source thumbnails from rel attribute */
afterLoad: function(){ sizeThumbs(); } /* Call the resize function */
});

Ta-da!  The only problem is, sometimes the JavaScript beats the browser to the finish line: it is calculating the height before the images have fully loaded, thus giving inaccurate values.  The solution?  Alter the function and setup a timer to make sure we’re fully loaded.

var last_height = 0; /* Initiate height logging variable in global scope */
function sizeThumbs(){
    var thumb_height = $(".nivo-controlNav").height();
    var gal_height = $("#slider").height();
    var this_height = (thumb_height+gal_height); /* Calculate total height */
    $("#gallery").height( this_height );
    /* Compare to last height and call function again if necessary */
    if ( this_height != last_height ) setTimeout( function(){ sizeThumbs(); }, 750 );
    last_height = this_height;
}
Amazon Kindle Fire and Silk Web Browser

It’s usually news when a device gets a big hardware upgrade, but’s especially interesting when there’s new software involved. The new Kindle Fire from Amazon is a turbocharged tablet, hardly drawing any comparison to their eInk powered eBook reader. It runs on Google Android technology, and even more impressive – Amazon built a new browser and cloud caching system, Silk. We can’t wait to get our hands on the specs and learn how best to optimize for consumption on this new device.

Yikes! Hate to see this. A client called this morning, one of the last few that host themselves, to report their server had bit the dust and could we host their site from a recent backup. They’re already back online!

Yikes! Hate to see this. A client called this morning, one of the last few that host themselves, to report their server had bit the dust and could we host their site from a recent backup. They’re already back online!

Really slick photo manager interface powered by jQuery.  Clockwise from top-left are the basic interface; sortable images within listings; drag and drop photos to listings; multiple file upload.

Really slick photo manager interface powered by jQuery.  Clockwise from top-left are the basic interface; sortable images within listings; drag and drop photos to listings; multiple file upload.

[Flash 10 is required to watch video]

Watch us design concept artwork for a client using Photoshop

Mobile site design, optimized for iPhone, for the Regional Food Bank of Oklahoma.

Mobile site design, optimized for iPhone, for the Regional Food Bank of Oklahoma.

I don’t know much about the physicist, but I like his Google Doodle today!

I don’t know much about the physicist, but I like his Google Doodle today!

Website concept artwork this week shows a dark theme

Website concept artwork this week shows a dark theme