Skip to content
Plugin PantryPlugins

Documentation / Pantry Code

Pantry Code

Contents: Scripts and snippets in the head, body and footer.

Scripts and snippets in the head, body and footer. Nothing else.

What it does

  • One settings screen (Plugin Pantry > Code) with three boxes: Head, Body and Footer. Whatever you paste prints exactly where the label says, on every front-end page.
    • Head prints on wp_head.
    • Body prints on wp_body_open, immediately after the opening <body> tag (on any theme that calls wp_body_open(), which every WordPress default theme since 5.2 does).
    • Footer prints on wp_footer, just before </body>.
  • A meta box with the same three boxes on every public post type, for a snippet that should only run on that one post or page. Per-post snippets print in addition to the site-wide ones, in the same three positions.
  • An "Options" section with one switch: skip printing any snippet for logged-in users, useful for analytics you do not want counting your own visits.
  • Editing either the settings screen or the meta box requires the unfiltered_html capability. Without it, or when the DISALLOW_UNFILTERED_HTML constant is set to true, both screens show the fields as read-only with a notice, and the server refuses to save any change to the snippet content even if a request is sent directly (other settings, such as the logged-in switch, still save).
  • Snippets never print in wp-admin, on wp-login.php, or on a REST API response.

What it does not do

  • No PHP execution: snippets are HTML/CSS/JS text, printed as-is.
  • No conditional rules by post type, URL, role or device.
  • No snippet library or list of saved, individually-toggled snippets.
  • No tag manager helpers.

These are deliberate scope limits from the Pantry Standard, not missing features. See does_not in the plugin's registry entry and https://thepluginpantry.com/standard.

Usage

  1. Activate the plugin.
  2. Go to Plugin Pantry > Code.
  3. Paste your snippet (a <script> tag, a <meta> verification tag, an analytics stub, and so on) into the box for the position you want: Head, Body or Footer.
  4. Save. The snippet prints on every front-end page from then on.
  5. To scope a snippet to one post or page, open that post's editor and use the "Pantry Code snippets" meta box near the bottom of the screen. Those three boxes work the same way but only print on that single post.

Only users who can publish unfiltered HTML (by default, Administrators on a single site; nobody on a subsite of a multisite network) can edit or save snippet content. Everyone else sees the same three boxes, but read-only.

Storage

  • Settings are stored in one option, pantry_code_settings, holding head_snippet, body_snippet, footer_snippet and skip_logged_in.
  • Per-post snippets are stored as three post meta keys: pantry_code_head, pantry_code_body and pantry_code_footer.
  • Snippet text is stored exactly as submitted, with wp_unslash() only. It is not filtered, escaped or checked in any way, on the way in or on the way out. That is the point of the plugin: what you paste is what runs. Treat the unfiltered_html capability accordingly.

Hooks

Pantry Code adds no filters or actions of its own. It hooks into the standard WordPress wp_head, wp_body_open, wp_footer, add_meta_boxes and save_post hooks, and reads the built-in unfiltered_html capability and the DISALLOW_UNFILTERED_HTML constant. There is nothing plugin-specific to filter.

Uninstall

Deleting the plugin through the Plugins screen removes the pantry_code_settings option and the three pantry_code_* post meta keys from every post. There are no custom tables, post types or cron events.

Comparison

How Pantry Code compares with the popular plugins that do the same job, and when one of them is the better choice.

Pantry Code compared with WPCode, Code Snippets and Header Footer Code Manager

The plugin