Postscript (WordPress Plugin)

For Data Visionaries and Multi-Mediators. The Postscript plugin for WordPress lets you:

  • 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.

No more shoehorning stylesheets and JavaScripts into the post content box, creating a spaghetti code mess.
Cluttered post content box before using Postscript plugin
Before Postscript: Content cluttered with scripts.
Clean post content box after using Postscript plugin
After Postscript: Clean post content box.

Download Postscript from the WordPress plugin directory.

script
The Postscript plugin taps into the built-in WordPress “enqueue” methods. This means you can:

  • 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

Postscript plugin meta box on Edit Post screen
Postscript meta box.

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:

  • A stylesheet URL.
  • Two JavaScript URLs, e.g, one JSON data file and one script file.
  • Add post and body classes

    And for each post, you can add a:

  • Body class to the HTML <body> tag (requires body_class() in theme).
  • Post class to 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.

    style

    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.

    Text animations from Codrops