Loading jQuery Poorly and Not Reading The Code Comments

I had to chuckle a bit when Eric Mann sent this snippet to me. I’ll let his words do the explaining for you:

Ironically, after writing a post explaining why you should never try to replace the version of jQuery bundled with WordPress with your own, I was asked to review why one of my plugins was not working on a specific site. I load some JS in the footer (using wp_enqueue_script() with the last argument set to true) that declares both jQuery and jQuery UI as depedencies.

Both dependencies load in the header just fine. But for some reason, jQuery UI is no longer available when the browser gets to my script at the bottom. It turns out, the theme author is manually including an older version of jQuery in the header, after calling wp_head(). This new include overwrites the global jQuery object, blocking jQuery UI and making my plugin’s scripts throw an error.

Ironically, the theme includes a note directly above the call to wp_head() to remind the developer it needs to be the last thing in the header because plugins are registering scripts and styles that could break otherwise.

<?php
  /**
   * header.php
   */
?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
 
<head>
<!-- meta tags and such omitted for brevity -->
 
  <?php
	/* Always have wp_head() just before the closing </head>
	 * tag of your theme, or you will break many plugins, which
	 * generally use this hook to add elements to <head> such
	 * as styles, scripts, and meta tags.
	 */
	wp_head();
  ?>
 
 
  <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
 
  <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
  <script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/js/jquery-1.6.min.js"></script>
  <script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/js/jquery.fancybox-1.3.4.js"></script>
  <script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/js/site.js"></script>
</head>

It’s clear that this theme author used a sample theme (not the comment about wp_head()), but one would think that he/she would have at least taken the time to read the words right in front of them when placing their code into the header.php file.

Advertisements

2 thoughts on “Loading jQuery Poorly and Not Reading The Code Comments

  1. This person was told that those lines of code should go right before so, that´s he/she did! Why waste time reading anything else?

    People don´t like to read superfluous things nowadays, the only problem being that what was written over there was not superfluous at all.

    But, you know, same thing applies to blog posts, for instance. People don´t like to read the whole thing, once they´ve read the sentence or opinion they were looking for or that was already in their mind.

    After all, we´re only humans, and we have to face an overwhelming amount of information every day. So, thoroughly reading seems to be an activity which has become either a waste of time or a kind of luxury for many.

  2. Sorry. In my previous comment, I meant “This person was told that those lines of code should go right before the closing of the “head” section so, that´s what he/she did!

    (I used the “/head” tag, so the comment went wrong), sorry about that.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s