---
description: >-
  https://www.it-swarm-vi.tech/vi/javascript/wp-add-inline-script-khong-phu-thuoc/963571362/
---

# wp\_add\_inline\_script không phụ thuộc (ok)

[https://www.it-swarm-vi.tech/vi/wp-admin/toi-co-them-thuoc-tinh-tuy-chinh-trong-khi-them-tap-lenh-noi-tuyen-khong/961931534/](https://www.it-swarm-vi.tech/vi/wp-admin/toi-co-them-thuoc-tinh-tuy-chinh-trong-khi-them-tap-lenh-noi-tuyen-khong/961931534/)

## Để hiển thị nó trong _đầu trang_&#x20;

```
Tôi có một đoạn mã javascript mà tôi muốn đưa vào phần cuối trang. Đó là mã theo dõi, giả sử tương tự như Google Analytics. Nó không có phụ thuộc, đó là một đoạn độc lập.
Tôi có thể làm một cái gì đó như thế này
```

```
// wp_add_inline_script
wp_register_script( 'dummy-handle-header', '/abcde.js' );
wp_enqueue_script( 'dummy-handle-header' );
wp_add_inline_script( 'dummy-handle-header', 'console.log( "headerlionel" );' );
```

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-M9biml7q48ecNYvh76R%2F-M9blBiOkQJ-z3ULfqLL%2F1.png?alt=media\&token=98543176-02d1-45a7-ae37-f4ea665096ad)

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-M9biml7q48ecNYvh76R%2F-M9blEgl4Bt09xijOcJh%2F2.png?alt=media\&token=d4a352dd-adec-4da3-920a-9e6cd16c5906)

```

wp_register_script( 'dummy-handle-header', false );
wp_enqueue_script( 'dummy-handle-header' );
wp_add_inline_script( 'dummy-handle-header', 'console.log( "headerlionel" );' );
```

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-M9biml7q48ecNYvh76R%2F-M9blMd_t2f1iElaMRSQ%2F3.png?alt=media\&token=6a1e0d15-8943-44e1-add8-c108d2f67e57)

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-M9biml7q48ecNYvh76R%2F-M9blRJbcBiIxCB2Rzme%2F4.png?alt=media\&token=7432edb1-59be-48c4-b6c8-90a9d42bc1c6)

## &#x20;Để hiển thị nó trong _chân trang_

```
wp_register_script( 'dummy-handle-footer', false, [], '', true );
wp_enqueue_script( 'dummy-handle-footer'  );
wp_add_inline_script( 'dummy-handle-footer', 'console.log( "lionelfooter" );' );
```

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-M9blTAMfRXhA_YbMZzY%2F-M9bmUF2t_wB_oErEFah%2F5.png?alt=media\&token=aa8a2e42-d236-4c2a-a75c-f4cf9caaae31)

![](https://2370029328-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LWPtKFbhw0XehxVuoiZ%2F-M9blTAMfRXhA_YbMZzY%2F-M9bmWmchJ9yfAdGKhR5%2FScreenshot_6.png?alt=media\&token=483e8dbd-adf2-4291-9ef2-1bf672f400cc)
