|
2 | 2 |
|
3 | 3 | <Badge type="tip" vertical="top" text="Elementor Core" /> <Badge type="warning" vertical="top" text="Intermediate" /> |
4 | 4 |
|
5 | | -Some addons have custom frontend scripts loaded to the client side on pages built with Elementor. In these cases, use `elementor/frontend/before_register_scripts` or `elementor/frontend/after_register_scripts` action hooks, which are fired when Elementor frontend scripts are registered and enqueued. |
| 5 | +Some addons have custom frontend scripts loaded on pages built with Elementor. Use `elementor/frontend/before_enqueue_scripts` or `elementor/frontend/after_enqueue_scripts` action hooks, which are fired when Elementor frontend scripts are registered and enqueued. |
6 | 6 |
|
7 | 7 | ## Registering Frontend Scripts |
8 | 8 |
|
9 | 9 | In the example below, we'll register and enqueue custom scripts **before** Elementor frontend scripts are registered and enqueued: |
10 | 10 |
|
11 | | -```php {11} |
12 | | -function my_plugin_frontend_scripts() { |
13 | | - |
| 11 | +```php {6,12} |
| 12 | +function my_plugin_register_frontend_scripts() { |
14 | 13 | wp_register_script( 'frontend-script-1', plugins_url( 'assets/js/frontend-script-1.js', __FILE__ ) ); |
15 | 14 | wp_register_script( 'frontend-script-2', plugins_url( 'assets/js/frontend-script-2.js', __FILE__ ), [ 'external-library' ] ); |
16 | 15 | wp_register_script( 'external-library', plugins_url( 'assets/js/libs/external-library.js', __FILE__ ) ); |
| 16 | +} |
| 17 | +add_action( 'elementor/frontend/before_register_scripts', 'my_plugin_register_frontend_scripts' ); |
17 | 18 |
|
| 19 | +function my_plugin_enqueue_frontend_scripts() { |
18 | 20 | wp_enqueue_script( 'frontend-script-1' ); |
19 | 21 | wp_enqueue_script( 'frontend-script-2' ); |
20 | | - |
21 | 22 | } |
22 | | -add_action( 'elementor/frontend/before_register_scripts', 'my_plugin_frontend_scripts' ); |
| 23 | +add_action( 'elementor/frontend/before_enqueue_scripts', 'my_plugin_enqueue_frontend_scripts' ); |
23 | 24 | ``` |
24 | 25 |
|
25 | 26 | Now we'll register and enqueue custom scripts **after** Elementor frontend scripts are registered and enqueued: |
26 | 27 |
|
27 | | -```php {11} |
28 | | -function my_plugin_frontend_scripts() { |
29 | | - |
| 28 | +```php {6,12} |
| 29 | +function my_plugin_register_frontend_scripts() { |
30 | 30 | wp_register_script( 'frontend-script-1', plugins_url( 'assets/js/frontend-script-1.js', __FILE__ ) ); |
31 | 31 | wp_register_script( 'frontend-script-2', plugins_url( 'assets/js/frontend-script-2.js', __FILE__ ), [ 'external-library' ] ); |
32 | 32 | wp_register_script( 'external-library', plugins_url( 'assets/js/libs/external-library.js', __FILE__ ) ); |
| 33 | +} |
| 34 | +add_action( 'elementor/frontend/after_register_scripts', 'my_plugin_register_frontend_scripts' ); |
33 | 35 |
|
| 36 | +function my_plugin_enqueue_frontend_scripts() { |
34 | 37 | wp_enqueue_script( 'frontend-script-1' ); |
35 | 38 | wp_enqueue_script( 'frontend-script-2' ); |
36 | | - |
37 | 39 | } |
38 | | -add_action( 'elementor/frontend/after_register_scripts', 'my_plugin_frontend_scripts' ); |
| 40 | +add_action( 'elementor/frontend/after_enqueue_scripts', 'my_plugin_enqueue_frontend_scripts' ); |
39 | 41 | ``` |
40 | 42 |
|
41 | 43 | ::: warning Please Note |
|
0 commit comments