---
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-05-29
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

- Update a code snippet in WordPress using the nexter/update-snippet ability by providing the required id parameter.
- Retrieve the current state of a snippet with nexter/get-snippet before making updates to ensure accuracy.
- Use nexter/toggle-snippet to change only the active state of a snippet without altering other fields.

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