751 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
CyberShot says

I am not sure what to do here. The codex doesn’t have a bunch of information. When loading scripts into your WordPress theme, do you have to register the script first or can you just enqueue it? Both seem to do the same thing.

3434 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 more
sevenspark Volunteer moderator says

Registering it just registers the map of $handle to $src. Registering a script will not automatically load it on your site.

Enqueue actually queues the script to be loaded into the markup.

Enqueue will automatically do the registering, so generally you don’t need to use wp_register_script at all.

For registered scripts, you can enqueue them simply by calling wp_enqueue_script on the $handle, without passing the other arguments.

Hope that clears it up :)

EDIT

In other words,

//register and enqueue myscript in one step
wp_enqueue_script( 
  'myscript',
  'path/to/myscript.js',
  array( 'jquery' ),
  '1.2',
  true
);

is equivalent to

//register myscript (tell WordPress it exists and where to find it)
wp_register_script( 
  'myscript',
  'path/to/myscript.js',
  array( 'jquery' ),
  '1.2',
  true
);
//enqueue myscript (actually add it to the page)
wp_enqueue_script( 'myscript' );
751 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
CyberShot says

it does, although still a little confusing. I just don’t see any reason to have wp_register_script if enqueue does the same thing.

894 posts
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+5 more
infuse01 says

There are some situations where this could come in handy – for example if your theme or plugin has used a script for quite a while and other plugins depends on this script > Compatibility.

But in most cases wp_enqueue_script() is enough

707 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+2 more
ChillThemes says

Here’s an article about it: http://wpcandy.com/teaches/how-to-load-scripts-in-wordpress-themes

Using wp_register_script() and wp_enqueue_script() together also makes things more organized and easier to keep track of. I personally, just use wp_enqueue_script()

751 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
CyberShot says

some good information. Thanks guys

3434 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 more
sevenspark Volunteer moderator says

One other reason register_script exists is so that WordPress can register all of the scripts that it packages in the core product and allow the developer to simply call wp_enqueue_script( ‘jquery’ ) for instance, without worrying about src paths, etc.

751 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
CyberShot says

Now that is the reason that prompted the “aha” moment in my head.

by
by
by
by
by
by