Postscript (WordPress Plugin)
- Enqueue scripts and stylesheets for individual posts.
- Track which posts use which script/style files.
- Optimize script/style load for best page performance.
No more loading scripts site-wide on every post that only a few posts use.
Download Postscript from the WordPress plugin directory.
- Clean up the post content box.
- Improve site performance.
- Control dependencies (when registering scripts).
- Load styles in the head and scripts in the footer.
- Eliminate loading multiple copies of the same library (jQuery, I’m looking at you).
What it does
Enqueue registered styles and scripts (by handle)
Use the Postscript meta box (Edit Post screen) to enqueue registered of styles and scripts (listed in checkboxes by handle.).
Enqueue unregistered styles, scripts, and data files (by URL)
For each post, you can also enqueue unregistered files, by entering in the meta boxes text fields for:
Add post and body classes
And for each post, you can add a:
<body>
tag (requires body_class()
in theme).class="post"
list (inserted by WordPress, requires post_class()
in theme).See the screenshots.
Credits
Thanks: This plugin was developed as part of a Reynolds Journalism Institute fellowship.
How to register scripts and styles in WordPress
Your scripts and styles
You can register your own CSS/JS file handles with the wp_register_script() and the wp_register_style() functions.
Only handles you register via the wp_enqueue_scripts
hook list on Postscript’s Settings screen. This list also has handles registered by your active theme and plugins and the defaults registered by WordPress itself.
Default scripts and styles
WordPress registers numerous styles and scripts via its core functions: wp_default_scripts() and wp_default_styles(). Each file gets its own unique handle: see the list of defaults.
Example: Thickbox
WordPress ships with a modified ThickBox jQuery library, used to make modal lightbox windows. The add_thickbox() function enables this feature, but it also loads Thickbox’s CSS and JS files on every Post, whether or not the post needs it.
This plugin improves site performance by only enqueuing scripts only when speficially requested for an individual post, by checking the Thickbox Script and Styles handles in the Postscript box. See the screenshots.
Example: Soundcite
Listen to “The Singing Frogs of the Pantanel” (3:30) by Tom Lopez of ZBS. Or maybe you’d prefer doing some “Office Yoga” (2:10) with Rebecca Flowers.
Contribute
Postscript is now on GitHub. Pull Requests welcome.