tailieunhanh - Hướng dẫn tạo themes cho wordpress part 20

Điều này có chứa một xử lý (tên của kịch bản, một chuỗi chữ thường) và URL (cũng là một chuỗi ký tự) mà kịch bản có thể được tìm thấy. Khi bạn gọi wp_enqueue_script, bạn phải vượt qua trong một chuỗi giá trị với giá xử lý như tham số đầu tiên, và URL ($ src) mà tại đó các tập lệnh có thể được tìm thấy như là các tham số thứ hai. | Chapter 10 How it works. When you call wp_enqueue_script you re taking advantage of one of several JavaScriptspecific functions included with WordPress. Some of the others include wp_register_ script wp_is_script and wp_print_scripts. The wp_enqueue_script function accepts the following parameters handle src deps ver and in_footer. Let s talk about which ones are required and which ones are optional. Earlier in our example we used the following function to call a simple JavaScript file wp_enqueue_script my-theme get_bloginfo stylesheet_ directory . js This contained a handle the name of the script a lowercase string and the URL also a string where the script could be found. When you call wp_enqueue_script you must pass in a string value for handle as the first parameter and the URL src at which the script can be found as the second parameter. These are the required parameters. Optionally you can pass in an array of script handles as a third parameter the dep parameter a version string as the fourth parameter the ver parameter and a flag in_footer a Boolean value indicating that the script should be printed in the footer as the fifth and final parameter. After a script has been enqueued WordPress knows that a link to it should be printed whenever wp_print_scripts is called. Normally this is called within the wp_head function inside of the head tag. When you are creating a theme using multiple JavaScript functions aL or feature-rich libraries such as JQuery it is a best practice to place the wp_enqueue_script function in and use 3 the in_footer parameter to automatically call the script in the footer. We will cover that in the next section. If you go back and check the source for your blog homepage after adding the code specified previously you ll see something like the following script type text javascript src http wp-content themes my-theme js my-theme. js ver script You can see that WordPress parsed the relative path .