---
title: "Update Snippet Ability: Edit a Code Snippet by ID in WordPress"
url: https://nexterwp.com/docs/nexter-update-snippet/
date: 2026-05-29
modified: 2026-08-19
author: "sandip patel"
description: "The nexter/update-snippet ability updates an existing Nexter Extension code snippet by ID. Pass any combination of fields to change. Only the fields you provide are updated."
word_count: 295
---

# Update Snippet Ability: Edit a Code Snippet by ID in WordPress

## Key Takeaways

- nexter/update-snippet updates an existing Nexter Extension code snippet by its ID, and only the fields passed are saved.
- The id parameter is required, while name, code, type, description, tags, location, priority, include_rules, exclude_rules, start_date, and end_date are optional.
- Nexter Extension (Free) ships with this ability, and nexter/list-snippets helps find the snippet ID before calling it.

The **nexter/update-snippet** ability updates an existing Nexter Extension code snippet by its ID. Pass the snippet ID and any fields you want to change. Only the fields you provide are saved. All other fields remain at their current values. Use nexter/get-snippet to read the current state before updating.

## Key Takeaways

The id parameter is required. All other parameters are optional.

Only the fields you pass are updated. Omitted fields keep their existing values.

Use nexter/list-snippets to find the snippet ID before calling this ability.

To change only the active state, use nexter/toggle-snippet instead.

## Required Setup

This ability ships with Nexter Extension (Free). If you do not have it installed, follow the guide on how to install and activate Nexter Extension first.

## Parameters

**id** (string, required) is the unique identifier of the snippet to update.

**name** (string, optional) updates the snippet's display name.

**code** (string, optional) replaces the snippet's code content.

**type** (string, optional) changes the snippet type. Options: php, css, javascript, htmlmixed.

**description** (string, optional) updates the snippet's description.

**tags** (array, optional) replaces the snippet's tag list.

**location** (string, optional) sets where the snippet runs (e.g., header, footer, body).

**priority** (integer, optional) controls the execution order relative to other snippets.

**include_rules** and **exclude_rules** (arrays, optional) control which pages or conditions trigger the snippet.

**start_date** and **end_date** (strings, optional) set the date range during which the snippet is active.

## What It Returns

The ability returns **success** (boolean) and the full updated snippet object with all current field values.

## When to Use This Ability

Fix a bug in an existing PHP or JavaScript snippet without deleting and recreating it.

Update display conditions to change where a snippet is injected on the frontend.

Set start and end dates to schedule a snippet for a specific campaign or time-limited feature.

## Related Documentation

Get Snippet Ability: nexter/get-snippet

Create Code Snippet Ability: nexter/create-snippet

Toggle Snippet Ability: nexter/toggle-snippet

## Frequently Asked Questions

**Q: Why does my snippet update keep changing the wrong code snippet in WordPress?**
A: The update call targets a snippet by its ID, so the usual failure mode is using the wrong ID. Nexter Extension provides `nexter/list-snippets` to find the correct snippet ID first, and `nexter/get-snippet` to read the current state before updating. That matters because `nexter/update-snippet` only saves the fields you send, while everything else stays unchanged.

**Q: Can I update just the active state of a code snippet without editing the rest?**
A: For an active-state-only change, `nexter/toggle-snippet` is the cleaner choice. `nexter/update-snippet` is built for editing fields like name, code, type, description, tags, location, priority, include_rules, exclude_rules, start_date, and end_date. Using the toggle ability avoids touching unrelated snippet data when all you want is on or off.

**Q: What fields can I change when updating a Nexter Extension code snippet by ID?**
A: `nexter/update-snippet` can update name, code, type, description, tags, location, priority, include_rules, exclude_rules, start_date, and end_date. The `type` field accepts `php`, `css`, `javascript`, or `htmlmixed`, and `location` can be set to places like header, footer, or body. That makes it useful for both content edits and display-condition changes.

**Q: Does updating a snippet overwrite fields I don't send?**
A: No. Only the fields you provide are saved, and every omitted field keeps its current value. That behavior is useful when you want a small fix without risking unrelated settings like tags or display rules. Nexter Extension returns the full updated snippet object afterward, so you can confirm the final state in one response.

**Q: When should I use update-snippet instead of deleting and recreating a snippet?**
A: Use `nexter/update-snippet` when you need to fix an existing PHP or JavaScript snippet without losing its current setup. It also fits cases where you want to change where a snippet runs on the frontend by editing location or display conditions with include_rules and exclude_rules. That preserves the original snippet ID and current values you are not changing.

**Q: How do I schedule a WordPress code snippet for a limited time?**
A: `nexter/update-snippet` supports `start_date` and `end_date`, so you can set a date range for a campaign or time-limited feature. That is more precise than leaving a snippet always active because it lets Nexter Extension control when it should run. Pairing dates with location or rules is useful when timing matters as much as placement.
