doze79040 2016-09-23 06:28
浏览 412

wp_enqueue_script()和wp_register_script()之间有什么区别

I am not clear when/where I will use wp_enqueue_script() or wp_register_script()

  • 写回答

3条回答 默认 最新

  • donglu9896 2016-09-23 06:39
    关注

    In simple words;

    wp_enqueue_script means, Add in a queue to register the file
    wp_register_script means, Register the file immediately

    wp_register_script registers a script to be enqueued later using the wp_enqueue_script() function.

    wp_enqueue_script() registers the script if $src provided (does NOT overwrite), and enqueues it. source: Developer.wordpress

    Here is brief Answer on WordpressDevelopment

    wp_register_script( $handle, $src, $deps, $ver, $in_footer );

    Scripts that have been pre-registered using wp_register_script() do not need to be manually enqueued using wp_enqueue_script() if they are listed as a dependency of another script that is enqueued. WordPress will automatically include the registered script before it includes the enqueued script that lists the registered script’s handle as a dependency.


    wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );

    wp_enqueue_script() links a script file to the generated page at the right time according to the script dependencies, if the script has not been already included and if all the dependencies have been registered. You could either link a script with a handle previously registered using the wp_register_script() function, or provide this function with all the parameters necessary to link a script.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line