Skip to content

Where on site#

A snippet prints on a page when any of its rules matches, minus pages matched by an exclusion. Rules are evaluated exactly as Simple Custom CSS and JS evaluates them, so a page gets the same snippets after the switch.

Rule types#

Rule Stored type Matches
All pages all Every request
Homepage first-page is_front_page()
URL contains contains The path and query contain the value
URL does not contain not-contains Exclusion
URL is equal-to The path and query equal the value
URL is not not-equal-to Exclusion
URL starts with begins-with The path and query start with the value
URL ends with ends-by The path and query end with the value
WordPress conditional wp-conditional A conditional tag expression is true

URL rules compare against the request path and query (REQUEST_URI), lowercased, with and without URL decoding. A value given as a full URL is reduced to its path, so the domain never matters and a rule written on staging works on production. URL is is exact: /pricing/ does not match /pricing or /pricing/?utm_source=x.

Order of evaluation#

  1. Union of the positive URL rules (all, homepage, contains, is, starts with, ends with).
  2. Minus every exclusion. Exclusions apply to every snippet that has them, so a snippet with only exclusions prints nowhere. BB Snippets keeps this behaviour for compatibility and shows a warning on such snippets.
  3. WordPress conditionals last: true adds the snippet, false removes it, and when a snippet has several conditionals they must all be true.

Conditional rules#

Conditionals are parsed, not run as PHP. The parser accepts calls to WordPress conditional tags with fixed arguments, combined with !, &&, ||, and, or and parentheses:

is_page( array( 293, 'pricing' ) )
is_singular( 'post' )
is_front_page() || is_home()
! is_page( 'pricing' ) && is_singular( array( 'page', 'post' ) )

Arguments may be strings, numbers, true, false, null and arrays (array( … ) or [ … ]). A leading return and a trailing ; are ignored.

Allowed tags: is_page, is_single, is_singular, is_front_page, is_home, is_archive, is_category, is_tag, is_tax, is_author, is_date, is_year, is_month, is_day, is_search, is_404, is_attachment, is_page_template, is_post_type_archive, is_paged, is_preview, is_feed, is_privacy_policy, is_sticky, has_term, has_category, has_tag, in_category, has_post_thumbnail, is_user_logged_in, is_admin, is_rtl, is_main_query, is_customize_preview, wp_is_mobile, is_ssl, is_multisite, is_main_site, get_post_type, get_the_ID, is_login.

A rule that does not parse never matches; the edit screen, the list and Tools → Health say which and why. Sites that need arbitrary PHP can restore eval() for such rules with:

define( 'BB_SNIPPETS_EVAL_CONDITIONALS', true );

That gives every snippet editor (the Web Designer role included) PHP execution on the server; see Security. define( 'CCJ_WP_CONDITIONALS', false ); turns conditional rules off entirely, as with the old plugin.

Shortcode snippets#

HTML snippets with the position As a shortcode ignore rules: they print wherever [ccj id="name"] is placed. Attributes fill placeholders, escaped for where they go: {$name} (text or a quoted attribute; javascript: values dropped), {$name|url}, {$name|js} (a JavaScript string), {$name|int}. Never inside an on…="" handler or an unquoted attribute. See Security.