WPCode Logo

WPCode Documentation

Documentation, Reference Materials, and Tutorials for WPCode

Most Popular

Get free tips and resources right in your inbox, along with 500+ others

Follow Us

What Type of Snippet Do I Need?

Would you like to know which snippet type to reach for before you paste in a single line of code?

In this guide, we’ll walk you through all eight WPCode snippet types and what each one changes in the snippet editor. All you need is the code you want to add and a few minutes to pick the right home for it.

Before you get started, make sure WPCode is installed and activated on your WordPress site.

Choosing a Code Type for a New Snippet

WPCode asks you to choose a code type as the very first thing you do in a new snippet. That makes the picker the best place to see all eight side by side.

To get there, go to Code Snippets » + Add Snippet in your WordPress admin sidebar.

The Add Snippet screen with the Code Snippets submenu open in the sidebar and + Add Snippet shown in bold

The Add Snippet screen opens on the Snippet Library tab. Hover over the Add Your Custom Code (New Snippet) card and click + Add Custom Snippet.

The Add Snippet screen with a red arrow pointing at the + Add Custom Snippet button on the Add Your Custom Code card

A blank snippet opens with the code type picker already showing. Each card names a type and describes what it is for. The card outlined in blue is the type you chose last.

Next, click the card for the type you need. The walkthrough below starts with HTML Snippet.

The WPCode code type picker showing all eight snippet type cards, with a red arrow pointing at the HTML Snippet card

Each type gets its own section below, in the same order its card appears in the picker.

Comparing the Eight Snippet Types

Every type saves to the same snippets list and shares the same insertion, conditional logic, and scheduling options. Three things change from type to type: the editor you get, how WPCode outputs your code, and which extra controls appear above the editor. In one case, the choice also changes which locations you can insert the snippet into.

If you already have your code in front of you, this list points you at the right section:

  • HTML for code you copied from another service, such as a tracking script, an ad tag, or a verification meta tag.
  • Text for wording you want to write and format rather than code you want to paste.
  • Blocks for a layout you prefer to build in the block editor rather than write by hand.
  • CSS for styling rules that change how your site looks.
  • SCSS for those same styles, written with SCSS nesting and variables.
  • JavaScript for code that runs in your visitor’s browser.
  • PHP for code that runs on the server, hooks into WordPress, or adds a function.
  • Universal for markup and PHP together in one snippet, the way a template file works.

HTML Snippets

HTML snippets suit anything you copy and paste from another service, such as a tracking script, an ad tag, or a verification meta tag. WPCode outputs the code exactly as you wrote it. Whatever the provider gave you is what lands on the page.

The editor gives you line numbers and syntax highlighting. The type you picked is always shown in the Code Type dropdown above it.

The Code Preview editor on an HTML snippet, showing highlighted HTML across three numbered lines with Code Type set to HTML Snippet

Text Snippets

Text snippets swap the code editor for the classic WordPress editor. They suit content you want to write and format rather than code you want to paste.

You get the familiar formatting toolbar, an Add Media button, and Visual and Code tabs. You can switch to markup whenever you need to.

WordPress adds paragraph formatting to the content when you save. Shortcodes from your other plugins are processed when the snippet runs. New to shortcodes? See What is Shortcode in WordPress? for a plain-English explanation.

The Code Preview area on a Text snippet, showing the classic WordPress editor with its formatting toolbar, Add Media button, and Visual and Code tabs

Blocks Snippets

Requirements: Blocks snippets are available in the paid versions of WPCode.

Blocks snippets let you build the snippet in the WordPress block editor. You can assemble a component from blocks instead of writing the markup by hand.

Choosing this type replaces the editor with an Edit with Block Editor button that loads the block canvas.

The Code Preview area on a Blocks snippet, showing the Edit with Block Editor button and its caption, with Code Type set to Blocks Snippet

CSS Snippets

CSS snippets hold styles. WPCode wraps them in a style tag when it outputs them, which means you write the rules on their own without any surrounding markup. The editor switches to CSS highlighting when you pick this type.

CSS snippets also add a Live Preview button next to Save Snippet. Live Preview opens your site with the styles applied so you can see the result before you make the snippet live.

The top of the snippet editor on a CSS snippet, showing the Live Preview button beside Save Snippet with Code Type set to CSS Snippet

SCSS Snippets

Requirements: SCSS snippets are available in the paid versions of WPCode.

SCSS snippets do the same job as CSS snippets, with SCSS syntax. You can use nesting and variables while you write.

WPCode compiles the SCSS to CSS when you save and outputs the compiled CSS in a style tag. Nothing extra runs in your visitors’ browsers.

SCSS snippets get the same Live Preview button as CSS snippets.

JavaScript Snippets

JavaScript snippets suit code you want to run in the browser. Write the JavaScript on its own, because WPCode wraps it in a script tag when it outputs it. If you paste in code that already has a script tag, WPCode removes it for you.

That last point matters when you are pasting a tag from another service. Those usually arrive with their own script tag already wrapped around them. In that case, choose HTML so the provider’s code goes out exactly as they gave it to you.

PHP Snippets

PHP snippets run on the server. That is what you want for anything that hooks into WordPress, changes how a page is built, or adds a function.

Write the PHP on its own, since WPCode strips the opening and closing PHP tags when you save. WPCode’s snippet generators produce PHP snippets when they add functionality, such as a custom post type or a scheduled task.

PHP is also the one type that reaches the PHP Snippets Only group in the location list. Those five locations run your code rather than printing it into the page. They are matched to the type that executes on the server.

A new PHP snippet also starts on a different location from the rest. It defaults to Run Everywhere, while the other seven types default to Site Wide Header. Our guide to snippet locations covers the full list.

The location list on a PHP snippet, showing the PHP Snippets Only group with Run Everywhere selected and Frontend Only, Admin Only, Frontend Conditional Logic, and On Demand also available

Universal Snippets

Universal snippets let you write HTML and PHP together in one snippet, the same way a template file does. You start in HTML, drop into PHP where you need a value, and come back out again. This suits template-style layouts and shortcodes that need to output markup and run logic at the same time.

Changing the Code Type

If you pick a type and then decide another one fits better, you do not need to start again. The Code Type dropdown above the code editor lists all eight types.

To switch, choose the type you want from the Code Type dropdown. Your code stays in the editor while you switch.

The Code Preview header with a red arrow pointing at the Code Type dropdown, which is set to HTML Snippet

That’s it! You now know what each WPCode snippet type does and which one fits the code you have.

Next, take a look at our guide to snippet locations to choose exactly where on your site the snippet runs.

Frequently Asked Questions

Below, we’ve answered some of the most common questions about WPCode snippet types.

Can I change a snippet’s type after I save it?

Yes. Open the snippet and pick a different type from the Code Type dropdown above the editor. Then click Save Snippet. WPCode stores whichever type is selected each time you save.

Which snippet types need a paid version?

Blocks and SCSS. In the free version, their cards in the picker are labeled Blocks Snippet (PRO) and SCSS Snippet (PRO).

Do I need to wrap JavaScript in script tags?

No. WPCode adds the script tag when it outputs a JavaScript snippet. If you paste code that already has one, WPCode removes it when you save.

Do I need PHP opening and closing tags in a PHP snippet?

No. WPCode removes a leading opening tag and a trailing closing tag when you save. You can paste code either way.

Which snippet types can use smart tags?

WPCode replaces smart tags in HTML, Text, JavaScript, and Universal snippets. If your snippet needs a value such as the current post title or the visitor’s first name, pick one of those four types. Smart tags need a paid version of WPCode.

What is the difference between a PHP snippet and a Universal snippet?

Both run PHP on the server. A PHP snippet expects PHP and nothing else, while a Universal snippet expects markup with PHP mixed into it, like a template file. One other difference matters when you choose: the five locations in the PHP Snippets Only group are available to PHP snippets. Reach for PHP when you need one of those.

Still stuck? How can we help?

Last Updated on

Get Started Today & Add Your Own Snippets

Future-proof your website with WPCode Snippets and improve the way you manage code across all your websites.