Now let’s break it down

We’re registering the scripts with wp_register_script()Read that page. Get in the practice of providing every parameter of the function every single time you register a script.
We’ve prefixed our function. Because, you need to prefix all the things. Use a prefix that makes sense, but isn’t “wp” or something else that could be used by core or other plugins. Your full initials, sitename, etc. are good possibilities.
As a sidenote, I recommend adding the action in your own theme setup function.
We are using an action hook called wp_enqueue_scripts(). It’s your best friend. This hook ensures that your function is registering and enqueuing scripts in the right place and only on the front end.


  1. Load in footer – If you set this to true, your script will be loaded in the footer, and therefore after much of the rest of the page has loaded. I always do this for things like sliders, because that way my slider script won’t prevent more important things on my page from loading. Just think about what you’re loading when you consider whether or not to do this.
  2. Version – The version of the script you are loading. If you update your script, you can bump the version, and when you change the version here, WordPress will be sure to load the new one, and reset any caching that’s been used on the previous version of your script.
  3.  Dependencies – These are the scripts your script depends on. You may recognize my scripts I’m loading. They’re two different slider scripts. They both depend on jQuery. You can pass multiple dependencies in this array, if necessary. For the script called “info-carousel-instance”, it relies on the “info-caroufredsel” script. Therefore when I enqueue “info-carousel-instance”, WordPress will know it needs to enqueue “info-caroufredsel” as well, if it hasn’t been enqueued already.
  4.  Handle – A name this script will go by. This is how you will enqueue it the short way, or if your user has a child theme and doesn’t want your script, they can dequeue it with this handle.
    1. Source – The path to the file. I used get_template_directory_uri(), which is a WordPress function that finds the parent theme directory. Never, ever, hard code the path with /wp-content or anything else. Use this function. It works. It’s great. If you are registering your script in a child theme, use get_stylesheet_directory_uri() instead. It’s the same thing, for child themes.

Yorumlar