Create Code Snippet Ability: Add PHP CSS JS and HTML in WordPress

Key Takeaways

  • Nexter Extension creates new snippets as inactive (status=0) by default to prevent accidental execution.
  • Nexter Extension supports PHP, CSS, JavaScript, and HTML snippet types with configurable insertion locations and execution scopes.
  • Nexter Extension allows scheduling snippets to run only within a specific date range using start_date and end_date parameters.
Table of Contents

The nexter/create-snippet ability creates a new code snippet in Nexter Extension. It supports PHP, CSS, JavaScript, and HTML snippet types with configurable insertion locations, execution scopes, scheduling dates, and display conditions. New snippets are created as inactive by default to prevent accidental execution. Use nexter/toggle-snippet with status=1 to activate after creation.

Key Takeaways

New snippets are created as inactive (status=0) by default to prevent accidental execution on creation.

For PHP snippets, do not include the opening tag. Nexter Extension adds it automatically.

Supported types are php, css, javascript, and htmlmixed.

Use start_date and end_date to schedule a snippet to run only within a specific date range.

The ability returns the new snippet ID so you can immediately reference it in toggle, update, or get calls.

Required Setup

The Code Snippets feature must be enabled in Nexter Extension. Use nexter/list-extensions to confirm it is active, or nexter/toggle-extension to enable it. After creating a snippet, use nexter/toggle-snippet with status=1 to activate it.

Parameters

Only name and type are required. All other parameters are optional and can be updated later with nexter/update-snippet.

name (string, required) sets the title of the snippet.

type (string, required) sets the code language. Options: php, css, javascript, htmlmixed. Defaults to php.

code (string, optional) is the source code. For PHP snippets, do not include the opening tag.

description (string, optional) is a brief note about what the snippet does.

tags (array of strings, optional) organizes the snippet into categories for easier filtering.

status (integer, optional) sets activation state. 1 = active, 0 = inactive. Defaults to 0.

insertion (string, optional) sets how the snippet runs. Options: auto, shortcode. Defaults to auto.

location (string, optional) sets where to execute. PHP: global, front-end, admin, wp_head, wp_body_open, wp_footer, before-content, after-content. CSS: header-css, footer-css. JS: header-js, footer-js. HTML: header-html, footer-html.

code_execute (string, optional) sets execution scope. Options: global, front-end, admin. Defaults to global.

priority (integer, optional) sets execution order. Lower numbers run earlier. Defaults to 10.

start_date and end_date (string, optional) schedule the snippet using ISO date format.

include_rules and exclude_rules (array, optional) set display conditions for showing or hiding the snippet on specific pages.

php_hidden_execute (string, optional) controls whether PHP output is hidden. Options: yes, no. Defaults to no.

What It Returns

The ability returns a confirmation object on success.

success (boolean) confirming the snippet was created.

id (string) of the newly created snippet for use in subsequent toggle, update, or get calls.

message confirming creation status.

When to Use This Ability

Add a PHP function, filter, or action to your site without editing theme or plugin files.

Inject CSS or JavaScript on specific pages using display conditions without a separate plugin.

Schedule a promotional script or banner to run only between a start date and end date.

Create a snippet as inactive first, review the code, then activate it with nexter/toggle-snippet when ready.

Related Documentation

nexter/toggle-snippet: Activate or deactivate a snippet after creation

nexter/list-snippets: View all existing snippets and their IDs

nexter/update-snippet: Edit an existing snippet code or settings

About the Author

sandip patel

WordPress Developer at POSIMYTH Innovations I am a passionate WordPress Developer at POSIMYTH Innovations, where I focus on building high-performance products and cutting-edge web experiences. Currently, I contribute to the development of major projects including The Plus Addons for Elementor, Sticky Header for Elementor, RankReady AI (LLM & SEO), and the SproutOS MCP server integration. I love bridging the gap between WordPress core functionality and modern AI capabilities. Beyond standard development.

Share your Thoughts

Get Instant Answers to all your questions about Nexter Blocks,
Extensions & Theme trained on 1000+ Docs and Videos

Still in Doubt? Let’s Assist You

Have Feedback or Questions?

Join our WordPress Community on Facebook!