Back to Community

Troubleshooting WPCode Special Character and Escaping Errors

19 threads Sep 10, 2025 PluginWpcode

Content

If you use the WPCode plugin to insert custom code on your WordPress site, you may have encountered frustrating error messages about special characters needing to be escaped. These errors, often mentioning characters like <, >, or &, can prevent you from saving your snippets or cause them to malfunction after saving.

This guide will explain why these errors occur and walk you through the most common solutions to resolve them, based on community experiences and solutions.

Why Do These Errors Happen?

The WPCode plugin includes a code validator designed to prevent syntax errors. This validator is context-aware, meaning its rules change based on the type of code you are writing (e.g., HTML, CSS, JavaScript, PHP). The error triggers when the validator detects a special character that could potentially break the code, but it expects that character to be used or escaped in a way that is correct for that specific code type.

Often, the root cause is a mismatch between the snippet type you've selected and the actual code you're trying to save.

Common Solutions to Special Character Errors

1. Verify and Correct Your Snippet Type

The most frequent solution, as seen in multiple threads, is ensuring your code's type matches the "Code Type" selected in the WPCode editor.

  • HTML Code: If you are inserting an <iframe> or raw HTML, the snippet type must be set to "HTML Snippet." Using a "Text" or other type will cause the validator to fail.
  • CSS Code: If you are writing CSS, select the "CSS Snippet" type. This allows for correct CSS comment syntax (/* */) and prevents errors from HTML-style comments (<!-- -->).
  • JavaScript Code: For JavaScript, use the "JavaScript Snippet" type and ensure your code is wrapped in <script> tags. This tells the validator to expect JS syntax.
  • PHP Code: Always use the "PHP Snippet" type for PHP code. The validator behaves differently here, but issues can arise if it incorrectly parses HTML within PHP strings.

2. Properly Escape Characters for Your Context

How you escape a character depends entirely on the language you are writing in.

  • In JavaScript: Within a string, you may need to use the backslash () escape character.
  • In HTML: Certain characters should be escaped using their HTML entities (e.g., &lt; for < or &amp; for &).
  • In PHP: The validator can sometimes misinterpret the intended use of characters within strings. If the editor is altering your code (e.g., changing &lt; back to <), this is a known display bug that the WPCode team has acknowledged and is working to fix. In many cases, the code still executes correctly despite the visual change in the editor.

3. Check for Plugin or Theme Conflicts

In some instances, the automatic conversion of characters is not done by WPCode but by another plugin or your theme. A common example is WordPress core or security plugins automatically adding rel="noopener" to links for security reasons, which can break JavaScript strings.

Troubleshooting Steps:

  1. Temporarily deactivate all other plugins except WPCode.
  2. Try to save your snippet again. If it works, reactivate your plugins one-by-one to identify the culprit.
  3. Temporarily switch to a default WordPress theme (like Twenty Twenty-Four) to rule out a theme-specific conflict.

4. Clear Your Cache

If your code snippet involves front-end changes (like CSS) that are only appearing on new pages but not old ones, the issue is likely caching. Clear any caching mechanisms you have running, including:

  • Your WordPress caching plugin (e.g., WP Rocket, W3 Total Cache).
  • Your server-level or CDN cache (e.g., Cloudflare).
  • Your browser cache.

Summary of Quick Fixes

Error Message / Symptom Likely Cause First Step to Try
"Special character must be escaped: [ < ]" on an iframe Snippet type is not "HTML" Change the "Code Type" to "HTML Snippet"
CSS comments not working, > shows error Snippet type is not "CSS" Change the "Code Type" to "CSS Snippet"
JavaScript code with && converts to && Conflict with another plugin or theme Perform a conflict test by disabling other plugins
PHP code with HTML entities reverts in editor Known display bug Test if the code works on the front-end despite the editor display
rel='noopener' automatically changes to rel="noopener" Quote conflict within a string Switch the outer quotes from double to single (or vice versa)

By methodically working through these steps—starting with double-checking your snippet type—you can usually resolve these special character and escaping issues in WPCode.

Related Support Threads Support