Skip to content

Toggle Snippet Ability: Enable or Disable a Code Snippet in WordPress

Key Takeaways

  • nexter/toggle-snippet enables or disables a Nexter Extension code snippet by its ID, with id required as a string and status using 1 for active or 0 for inactive.
  • Nexter Extension (Free) ships with the ability, and users must install and activate Nexter Extension first if it is not already installed.
  • Omitting status flips the snippet’s current active state, and disabling a snippet stops it from running without deleting its code or settings.
Table of Contents

The nexter/toggle-snippet ability enables or disables a Nexter Extension code snippet by its ID. Pass the snippet ID and an optional status value (1 for active, 0 for inactive). If you omit status, the ability flips the current state. Use nexter/list-snippets to find the snippet ID first.

Key Takeaways

The id parameter is required and is a string.

The status parameter uses integers: 1 for active, 0 for inactive.

When status is omitted, the ability flips the snippet’s current active state.

Disabling a snippet stops it from running without deleting its code or settings.

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 toggle.

**status** (integer, optional) sets the target state. Use 1 for active and 0 for inactive. Omit to flip the current state.

What It Returns

The ability returns: success (boolean), new_status (the state after the change — active or inactive), and message (a confirmation string).

When to Use This Ability

Quickly disable a PHP snippet that is causing errors on a live site.

Enable a snippet that was drafted but not yet activated.

Automate snippet activation as part of a site deployment or maintenance workflow.

Related Documentation

List Snippets Ability: nexter/list-snippets

Delete Code Snippet Ability: nexter/delete-snippet

Update Snippet Ability: nexter/update-snippet

Share your Thoughts

Still in Doubt? Let’s Assist You

Have Feedback or Questions?

Join our WordPress Community on Facebook!