简体   繁体   中英

In wordpress, why I should register and enqueue js scripts with wp_register_script() and wp_enqueue_script()?

为什么不在HTML内容中添加我需要的脚本?

Here are few reasons for WHY!

  • First of all, it makes you AWESOME among your friends
  • It helps define the dependencies of the script you are using, like won't need to enqueue other scripts like jquery, jquery-ui, thickbox or any other scripts if you have already registered one.
  • It makes your code more semantic, and your code will make more sense.
  • Your theme or plugin will have less chance of conflicting with other's (like double loading jquery files, fancybox files and so on)
  • You will have more control where you want the js to embed on pages with simple conditional tags like

if(is_page() || is_single()){ wp_enqueue_script(......); }

因为插件也需要一种添加脚本的方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM