Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

All docs

Smart tags

Smart tags are placeholders such as {post_title} or {user_email} that Snipfire replaces with the page's values when a snippet runs. Use them in HTML and JavaScript snippets, the Header & Footer boxes and page code, so one snippet can show the right title, link or name on every page.

<p class="share">Share "{post_title}": <a href="https://x.com/intent/post?url={post_url}">X</a></p>

Where they work

Where Replaced when
HTML snippets Replace smart tags is on for the snippet
JavaScript snippets Replace smart tags is on for the snippet
Header & Footer boxes Saving a box with a smart tag in it switches Replace smart tags on for you
Page code (one post or page) Always

Smart tags don't work in PHP or CSS snippets. In PHP, use WordPress's own functions (get_the_title(), wp_get_current_user()…). For values you choose yourself, such as a colour or an ID, use a settings form and {setting:key}, which works in CSS too.

In an HTML snippet that contains PHP, the PHP runs first and the tags are replaced in what it prints.

Switch them on

Tags are only replaced in snippets that ask for it, so code that happens to contain {word} (a JavaScript object, a template) is never changed behind your back.

  • In the settings panel, under Smart tags, tick Replace smart tags.
  • Or pick a tag from the { } Smart tags menu in the toolbar: it's inserted at the cursor, and Replace smart tags is switched on.
  • If you type a tag while the setting is off, the editor says This snippet contains smart tags such as {post_title}, but they aren't replaced yet. Click Replace smart tags.

The classic editor screen has the same Replace smart tags box. From the command line use --smart-tags (or --no-smart-tags) with wp snipfire create and update; in the REST API and abilities the field is smart_tags.

A JavaScript snippet with smart tags always loads inline, whatever Load as says, because its code is different on every page. See Loading CSS and JavaScript.

All tags

wp snipfire smart-tags lists them on your site, including any that add-ons add.

Site

Tag Value
{site_name} Site title
{site_url} Site address (the home page)
{login_url} Log-in link that brings the visitor back to this page
{logout_url} Log-out link (to the home page) for logged-in users; empty for visitors

This page

Tag Value
{page_url} Address of this page, with its query string
{page_title} Title of this page, as in the browser tab
{post_id} Post ID (a number)
{post_title} Post title
{post_url} Post link
{post_type} Post type key, for example post, page or product
{post_date} Post date, in the site's date format
{post_author_id} Author's user ID (a number)
{post_author_name} Author's display name
{post_author_url} Link to the author's posts
{post_categories} Categories, comma-separated
{post_tags} Tags, comma-separated
{custom_field:key} A custom field (post meta) of the post, for example {custom_field:subtitle}
{url_param:name} A parameter in the page address, for example {url_param:utm_source}

The post_… tags and {custom_field:…} use the post being shown. In a list of posts (the HTML locations before, after or between posts) they follow the loop, so each post gets its own values. On pages that aren't a single post, such as the search results, they're empty outside the loop.

{custom_field:key} gives a field's text or number. A field that holds a list or an object gives nothing. The key can have letters, numbers, _, - and ..

Logged-in user

Tag Value
{user_id} User ID, 0 for visitors
{user_email} Email
{user_first_name} First name
{user_last_name} Last name
{user_display_name} Display name
{user_role} The user's first role key, for example administrator or customer

For visitors who aren't logged in, these are empty (and {user_id} is 0).

Date

Tag Value
{date} Today's date, in the site's date format
{time} The time now, in the site's time format
{year} The year, for example in a footer: © {year}

Dates and times use the site's time zone (Settings → General).

Tags Snipfire doesn't know

A word in braces that isn't a tag, such as {color}, is left as it is. So are tags written the wrong way: {custom_field} without a key, or {post_id:5} with one it doesn't take.

How values are escaped

Snipfire escapes each value for where it lands, so a post title with quotes or < can't break your page or run as code.

In HTML (HTML snippets, the Header & Footer boxes, page code):

  • text is HTML-escaped (esc_html()),
  • link tags ({site_url}, {login_url}, {logout_url}, {page_url}, {post_url}, {post_author_url}) are cleaned as addresses (esc_url()).

In JavaScript snippets:

  • text and links are escaped for use inside a string, without the quotes. Put the quotes around the tag yourself: '{post_title}'.
  • number tags ({post_id}, {post_author_id}, {user_id}, {year}) go in as plain numbers, so write them without quotes. An empty number becomes 0.
var page = {
    id: {post_id},
    title: '{post_title}',
    loggedIn: {user_id} > 0
};

Inside a <script> in an HTML snippet, values are HTML-escaped, not JavaScript-escaped. For scripts that use smart tags, prefer a JavaScript snippet.

Page caching

If your site uses a page cache, a cached page shows the values of whoever the page was cached for. Tags that are the same for everyone on a page ({post_title}, {site_name}) are fine. Tags that depend on the visitor or the moment ({user_…}, {url_param:…}, {logout_url}, {time}) need pages that aren't cached, such as the account pages most caches already skip. See Conditions and page caching.

WooCommerce order tags Pro

With Snipfire Pro and WooCommerce active, there are tags for the order on the order-received (thank you) page, for conversion scripts such as a GA4 purchase event or an ad pixel. They're in the WooCommerce order (order-received page) group of the { } Smart tags menu.

Tag Value
{order_id} Order ID (a number)
{order_number} Order number, as the customer sees it
{order_status} Order status, for example processing
{order_total} Order total (a number)
{order_subtotal} Subtotal (a number)
{order_tax} Tax (a number)
{order_shipping} Shipping (a number)
{order_discount} Discount (a number)
{order_currency} Currency code, for example EUR
{order_item_count} Number of items (a number)
{order_product_ids} Product IDs, comma-separated (the variation ID for variations)
{order_coupons} Coupon codes, comma-separated
{order_payment_method} Payment method, as shown to the customer
{order_email} Customer's billing email
{order_first_name} Customer's billing first name
{order_last_name} Customer's billing last name
{order_country} Billing country, as a two-letter code
{order_items_json} The items as JSON: item_id (the SKU, or the product ID without one), item_name, price (per item, after discounts) and quantity
{order_first_view} 1 the first time the page is shown for this order, otherwise 0

Amounts use your shop's number of decimals. In a JavaScript snippet, the number tags and {order_items_json} go in as they are (no quotes); the others are strings.

Only on a real order page. The tags have values only on the order-received page, and only when its address has the order's key, as WooCommerce's own link does. A guessed order number shows nothing. On every other page they're empty ({order_items_json} is []).

Once per order. Customers reload the thank-you page or come back to it from the order email. Check {order_first_view} so a purchase is only sent once. Snipfire remembers on the order that the page was shown the first time the tag is used.

if ( {order_first_view} && typeof gtag === 'function' ) {
    gtag( 'event', 'purchase', {
        transaction_id: '{order_number}',
        value: {order_total},
        currency: '{order_currency}',
        items: {order_items_json}
    } );
}

The GA4 purchase event generator makes this snippet for you, set to run only on the order-received page.

The customer's email and name are personal data. Send them to another service only if your privacy policy and consent allow it: see Cookie consent.

Developers with a custom thank-you page can give the tags an order with the snipfire_smart_tags_order filter. See PHP hooks.

Add your own tags

Developers can add tags with the snipfire_smart_tags filter and give their values with snipfire_smart_tag_value. Snipfire escapes them like its own. See PHP hooks.

Something unclear or missing? Tell us