Description
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.
Installation
- Upload
/lightweight-js-snippet/to the/wp-content/plugins/directory. - Activate the plugin through the Plugins menu in WordPress.
- Go to Settings Lightweight JS snippet and paste in your JS plus the post IDs.
FAQ
-
Where does the script run?
-
It is printed inline in the
<head>of the listed posts/pages, only. -
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.
Reviews
There are no reviews for this plugin.
Contributors & Developers
“Lightweight JS Snippet” is open source software. The following people have contributed to this plugin.
ContributorsTranslate “Lightweight JS Snippet” into your language.
Interested in development?
Browse the code, check out the SVN repository, or subscribe to the development log by RSS.
Changelog
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 tomanage_optionspower 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 useesc_textarea()for the snippet field. - Add the missing
License,License URIandText Domainheaders, fix the text-domain mismatches, and add an explicit version towp_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.

