Title: Lightweight JS Snippet
Author: Jonas Hjalmarsson
Published: <strong>9 Tháng 9, 2022</strong>
Last modified: 23 Tháng 10, 2026

---

Tìm kiếm plugin

![](https://ps.w.org/lightweight-js-snippet/assets/banner-772x250.png?rev=3521626)

![](https://ps.w.org/lightweight-js-snippet/assets/icon-256x256.png?rev=3521626)

# Lightweight JS Snippet

 Bởi [Jonas Hjalmarsson](https://profiles.wordpress.org/jonashjalmarsson/)

[Tải về](https://downloads.wordpress.org/plugin/lightweight-js-snippet.1.4.2.zip)

 * [Chi tiết](https://vi.wordpress.org/plugins/lightweight-js-snippet/#description)
 * [Đánh giá](https://vi.wordpress.org/plugins/lightweight-js-snippet/#reviews)
 *  [Cài đặt](https://vi.wordpress.org/plugins/lightweight-js-snippet/#installation)
 * [Nhà phát triển](https://vi.wordpress.org/plugins/lightweight-js-snippet/#developers)

 [Hỗ trợ](https://wordpress.org/support/plugin/lightweight-js-snippet/)

## Mô tả

A minimal way to inject a single inline JavaScript snippet into the `<head>` of 
one or more specific posts, pages or products. You give it a comma-separated list
of post IDs and the JS body — that is the entire surface area.

The point is the absence of features. There is no per-post UI, no script library,
no CDN selector, no “fire on event” toggle. If all you need is to drop a tracking
pixel or a tiny script on three specific pages, you do not want a 2 MB plugin that
wants to manage your whole site.

Set it up under **Settings  Lightweight JS snippet**. The page provides a textarea
for the JS (no `<script>` tags — those are added for you) and a comma-separated 
list of post IDs to load it on.

## Ảnh màn hình

[⌊Settings page with code editor and post-ID list.⌉⌊Settings page with code editor
and post-ID list.⌉[

Settings page with code editor and post-ID list.

## Cài đặt

 1. Upload `/lightweight-js-snippet/` to the `/wp-content/plugins/` directory.
 2. Activate the plugin through the Plugins menu in WordPress.
 3. Go to **Settings  Lightweight JS snippet** and paste in your JS plus the post IDs.

## Hỏi đáp

### Where does the script run?

It is printed inline in the `<head>` of the listed posts/pages, only.

### Can I add `

No — they are added for you. Only paste the JS body.

### Does it support more than one page?

Yes. Use a comma-separated list of post IDs. Search for the post name in the settings
page to find the ID automatically.

## Đánh giá

Không có đánh giá nào cho plugin này.

## Người đóng góp & Lập trình viên

“Lightweight JS Snippet” là mã nguồn mở. Những người sau đã đóng góp vào plugin 
này.

Những người đóng góp

 *   [ Jonas Hjalmarsson ](https://profiles.wordpress.org/jonashjalmarsson/)

[Dịch “Lightweight JS Snippet” sang ngôn ngữ của bạn.](https://translate.wordpress.org/projects/wp-plugins/lightweight-js-snippet)

### Muốn tham gia phát triển?

[Duyệt code](https://plugins.trac.wordpress.org/browser/lightweight-js-snippet/),
check out [SVN repository](https://plugins.svn.wordpress.org/lightweight-js-snippet/),
hoặc theo dõi [nhật ký phát triển](https://plugins.trac.wordpress.org/log/lightweight-js-snippet/)
qua [RSS](https://plugins.trac.wordpress.org/log/lightweight-js-snippet/?limit=100&mode=stop_on_copy&format=rss).

## Nhật ký thay đổi

#### 1.4.2

 * Fixed: `>` and `&` in the JavaScript were saved as `&gt;` and `&amp;`, which 
   broke arrow functions and comparisons. Code saved earlier is repaired automatically.
 * Fixed: title search and lookup on the settings page failed on sites with plain
   permalinks.
 * Fixed: a `</script` inside the code can no longer end the script tag early.
 * The plugin’s settings are removed when it is deleted.

#### 1.4.1

 * Fix empty `<script id="jhljs-script">` tag rendered on every page when no snippet
   was configured. Logic error (`||` where `&&` was meant) plus no early-return 
   on empty options.
 * Fix Settings link on the Plugins screen — previous filter targeted the wrong 
   plugin basename, and the URL pointed at a non-existent menu slug. Both corrected.

#### 1.4

 * Settings page now lets you pick target posts/pages by typing their title — the“
   comma-separated post IDs” textbox is replaced with a chip-style picker. Two small
   REST endpoints (`jhljs/v1/posts`, `jhljs/v1/search`) gated to `manage_options`
   power the lookup and search.

#### 1.3

 * Sanitize the post-id list and the JS snippet on save via `register_setting()`
   callbacks (digits/commas/whitespace for the IDs, `wp_kses` `'data'` for the script—
   same filter that was already applied on output).
 * Escape every translated string in the settings UI (`_e()`/`__()`  `esc_html_e()`/`
   esc_html__()`) and use `esc_textarea()` for the snippet field.
 * Add the missing `License`, `License URI` and `Text Domain` headers, fix the text-
   domain mismatches, and add an explicit version to `wp_enqueue_script()`.
 * Bumped minimum PHP to 7.4. Tested up to WordPress 6.9.

#### 1.2

 * Bugfix when escaping script.

#### 1.1

 * Code editor added.
 * Support for multiple ids.
 * Securing plugin.

#### 1.0

 * Initial release.

## Meta

 *  Phiên bản **1.4.2**
 *  Cập nhật lần cuối **2 tuần trước**
 *  Số lượt cài đặt **Ít hơn 10**
 *  Phiên bản WordPress ** 5.0 hoặc cao hơn **
 *  Đã kiểm tra lên đến **7.1.4**
 *  Phiên bản PHP ** 7.4 hoặc cao hơn **
 *  Ngôn ngữ
 * [English (US)](https://wordpress.org/plugins/lightweight-js-snippet/)
 * Thẻ
 * [head](https://vi.wordpress.org/plugins/tags/head/)[inline](https://vi.wordpress.org/plugins/tags/inline/)
   [javascript](https://vi.wordpress.org/plugins/tags/javascript/)[post](https://vi.wordpress.org/plugins/tags/post/)
   [snippet](https://vi.wordpress.org/plugins/tags/snippet/)
 *  [Nâng cao](https://vi.wordpress.org/plugins/lightweight-js-snippet/advanced/)

## Đánh giá

Chưa có đánh giá nào được gửi.

[Your review](https://wordpress.org/support/plugin/lightweight-js-snippet/reviews/#new-post)

[Xem tất cả đánh giá](https://wordpress.org/support/plugin/lightweight-js-snippet/reviews/)

## Những người đóng góp

 *   [ Jonas Hjalmarsson ](https://profiles.wordpress.org/jonashjalmarsson/)

## Hỗ trợ

Có điều gì muốn nói? cần giúp đỡ?

 [Xem diễn đàn hỗ trợ](https://wordpress.org/support/plugin/lightweight-js-snippet/)

## Ủng hộ

Bạn có muốn hỗ trợ vào sự phát triển của plugin này?

 [ Ủng hộ plugin này ](https://jonashjalmarsson.se/help-me-out/)