---
title: Scope Settings
description: "Scope controls when and where each snippet runs or is loaded. ## PHP scope | Field | Description | | --- | --- | | Hook | The WordPress action hook to run the snippet on. Common values: `init`, `wp_loaded`,…"
url: "https://brightleafdigital.io/docs/scope-settings/"
updated: "2026-10-20"
category: GravityOps Code Snippet Manager / Managing Snippets
---

# Scope Settings

Scope controls when and where each snippet runs or is loaded.

## PHP scope

| Field | Description |
| --- | --- |
| Hook | The WordPress action hook to run the snippet on. Common values: `init`, `wp_loaded`, `template_redirect`. Default: `init`. |
| Priority | Hook priority. Lower numbers run earlier. Default: `10`. |
| Context | Where to run: **Everywhere**, **Frontend only**, **Admin only**, **Login page**, **REST requests**, or **Cron only**. **Admin only** and **Frontend only** skip AJAX requests, and **Frontend only** also skips REST requests. |
| Run once then deactivate | Checkbox, off by default. When checked, the snippet runs once and is then set to **Inactive** (its file is kept). Useful for one-time migration scripts. |

If the configured hook has already fired by the time GOCSM registers the snippet, GOCSM executes the snippet immediately for that request after checking the configured context.

## JS scope

| Field | Description |
| --- | --- |
| Context | **Everywhere**, **Frontend only**, **Admin only**, or **Login page only**. |
| Location | **Head** (default) or **Footer**. |
| Page targeting | Restrict loading to all pages, URL contains, URL regex, post types, or page templates. See [Page targeting](#page-targeting) below. |
| Dependencies | Comma-separated script handles that must load before this one (e.g. `jquery`). |
| Version | Script version string. Leave blank to use the generated file's modification time, which changes whenever the code or a config value changes. |
| Strategy | **defer** (default), **async**, or **Blocking**. Invalid values fall back to `defer`. |

## CSS scope

| Field | Description |
| --- | --- |
| Context | **Everywhere**, **Frontend only**, **Admin only**, or **Login page only**. |
| Page targeting | Same targeting options as JS. |
| Media query | CSS media attribute. Default: `all`. Example: `screen and (max-width: 768px)`. |
| Dependencies | Comma-separated stylesheet handles that must load before this one. |
| Version | Stylesheet version string. Leave blank to use the generated file's modification time, which changes whenever the code or a config value changes. |

## HTML scope

| Field | Description |
| --- | --- |
| Location | Where the markup prints. Front end: **Head**, **Start of body**, or **Footer** (default). Admin: **Admin head** or **Admin footer**. Login page: **Login head** or **Login footer**. **Shortcode only** prints the snippet only where its shortcode is placed. **Start of body** needs a theme that calls `wp_body_open()`. |
| Priority | Hook priority for the location. Lower numbers print earlier. Default: `10`. |
| Page targeting | Same targeting options as JS. Applies to the location only. |

The shortcode `[gocsm_snippet id="123"]` prints an active HTML snippet wherever it is placed, whatever its location setting. The **HTML Snippet** block does the same in the block editor: add the block and choose the snippet. The editor shows the snippet's name instead of a preview, because HTML snippets often contain scripts that should not run while you edit. Page targeting does not apply to the shortcode or block, and an inactive snippet prints nothing.

## Page targeting

JS, CSS, and HTML snippets can be limited to specific pages within their context:

| Option | How it matches |
| --- | --- |
| All pages (within context) | Every page in the chosen context. |
| URL contains | One entry per line. Matches when the requested URL path contains any entry (not case-sensitive). |
| URL regex | A regular expression matched against the requested URL path. Enter it without delimiters, e.g. `^/blog/`. The pattern is checked when you save. |
| Post types | Comma-separated post types, e.g. `post, page`. Matches single-item views of those types only. |
| Page templates | Comma-separated template filenames, e.g. `template-landing.php`. |

Post type and page template targeting never match on admin screens.
