Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared hosting Managed WordPress Cloud hosting VPS hosting By reader location Hosting finder
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Blog Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

Troubleshooting

WPCode Snippet Not Working: Causes and How to Fix It

WPCode Snippet Not Working: Causes and How to Fix It

Short answer

A WPCode snippet that does nothing is usually inactive, set to the wrong code type, inserted in the wrong location or limited by conditional logic. If it stopped suddenly, WPCode may have switched it off after a PHP error, so read the notice on the snippet screen and purge caches before testing again.

Key takeaways

  • New snippets stay inactive until you switch them on.
  • Match the code type to your code and avoid double script tags.
  • Shortcode snippets only run where the shortcode is placed.
  • WPCode deactivates PHP snippets that throw errors.
  • Purge caches and check the page source to confirm the code loads.
  • Rename the plugin folder over FTP if a snippet locks you out.

Why is your WPCode snippet not working?

A WPCode snippet usually fails because it is inactive, set to the wrong code type or location, blocked by conditional logic, cached, or deactivated by WPCode after an error.

WPCode, the plugin formerly called Insert Headers and Footers, lets you add PHP, JavaScript, CSS and HTML without editing theme files. Each snippet has settings that decide where and when it runs.

When a snippet does nothing, the code itself is often fine. One of those settings simply stops it from running on the page you are checking.

Less often, the code has an error. WPCode is built to catch PHP errors and switch the snippet off so your site keeps working.

If you are new to the plugin, our guide on how to use the WPCode plugin explains the snippet screen step by step.

What are the common causes at a glance?

Most WPCode problems match one of these causes, and each has a quick first check.

SymptomLikely causeFirst check
Nothing happens at allSnippet inactiveToggle it to Active and save
Code shows as text on the pageWrong code typeMatch PHP, JS, CSS or HTML
Works on some pages onlyLocation or conditional logicReview insertion and conditions
Was working, then stoppedAuto-deactivated after an errorCheck the snippet's error notice
Change not visiblePage or asset cachingPurge caches, test logged out
JavaScript error in consoleMissing dependency or load orderCheck console and script position

Match your symptom to the table, then use the section that fits.

Is the snippet active?

Open Code Snippets in WordPress, find your snippet and make sure its status switch is on, then click Update to save.

New snippets are saved as inactive until you switch them on. This is the most common reason a snippet does nothing.

  1. Go to Code Snippets in the dashboard menu.
  2. Find your snippet in the list.
  3. Check the status switch next to it.
  4. If it is off, open the snippet, turn the switch to Active and click Update.

If the switch turns itself off after saving, WPCode probably found an error. Look for a red notice at the top of the snippet edit screen.

Have you picked the right code type?

The code type must match your code, so choose PHP for PHP, JavaScript for scripts without script tags, CSS for styles and HTML for markup with tags.

WPCode treats each type differently. A mismatch is a common reason code appears as plain text on the page or does not run.

  • PHP Snippet. Runs on the server. Leave out the opening PHP tag, as WPCode adds it for you.
  • JavaScript Snippet. Enter only the code. WPCode wraps it in script tags.
  • CSS Snippet. Enter only the rules. WPCode wraps them in style tags.
  • HTML Snippet. Use this for tracking codes copied with their own script tags.
  • Universal Snippet. Mixes HTML, CSS, JavaScript and PHP in one block.

A tracking code that already includes script tags should go in an HTML snippet. Placing it in a JavaScript snippet adds a second set of tags and breaks it.

Is the insertion location correct?

The insertion location decides where the code runs, so check that the snippet uses Auto Insert with a location that matches your goal, or that you placed its shortcode.

Open the snippet and scroll to the Insertion box. You will see two methods:

  • Auto Insert. WPCode runs the code in a chosen location, such as everywhere, front end only, admin only, the site header or the site footer.
  • Shortcode. The code runs only where you paste the snippet's shortcode.

If the method is Shortcode but you never added the shortcode to a page, the snippet never runs. Switch to Auto Insert or place the shortcode.

PHP snippets that add hooks should usually Run Everywhere. A PHP snippet limited to the front end will not affect admin screens.

Scripts that need the page content to exist often work better in the footer. Our guide to adding Google Tag Manager to WordPress shows a typical header and body setup.

Is conditional logic hiding the snippet?

Conditional logic can limit a snippet to certain pages, users or devices, so turn it off temporarily to see if the snippet starts working.

In the snippet's Smart Conditional Logic box, rules such as Show only on a page type or Hide for logged-in users change when code runs.

A rule that targets the wrong page ID, post type or user role is easy to miss. Check each rule against the page you are testing.

To test quickly, switch conditional logic off, update the snippet and reload the page. If the code now works, rebuild the rules one at a time.

Did WPCode deactivate the snippet after an error?

When a PHP snippet triggers an error, WPCode deactivates it to protect the site and shows the error message, so read that message and fix the line it points to.

This protection is helpful. A bad PHP snippet in a theme file can take down the whole site, while WPCode switches it off and keeps the site running.

Open the snippet and read the error notice. It usually names a line number and a cause, such as a syntax error or an undefined function.

WPCode also has an error logging option in its settings that records snippet errors. The WPCode guide to debugging PHP errors explains how to turn it on and read the log.

For general PHP problems, the WordPress debugging guide shows how to enable WP_DEBUG and the debug log.

What PHP mistakes break snippets most often?

The most common PHP mistakes are a duplicate opening tag, a missing semicolon or bracket, a function name already in use, and code that runs before WordPress is ready.

Check your snippet for these problems:

  • Extra opening tag. Remove the opening PHP tag if you pasted it in.
  • Missing semicolon or bracket. One missing character stops the whole snippet.
  • Duplicate function name. If a theme or plugin already declares the same function, PHP throws a fatal error. Rename yours or wrap it in a function_exists check.
  • Wrong hook. Code that uses WordPress functions often needs to run on a hook such as init or wp_enqueue_scripts.
  • Old PHP syntax. Code copied from old tutorials may use functions removed in newer PHP versions.

The Plugin Handbook section on hooks explains when actions and filters run. The PHP manual helps when an error names a specific function.

Is caching hiding your changes?

Page caches and optimisation plugins can keep serving the old page, so purge every cache and test in a private window after changing a snippet.

If you added a script or style and nothing changes, the browser may be loading a cached copy. This is common with caching plugins and CDNs.

  1. Purge your caching plugin.
  2. Purge any host or CDN cache.
  3. Open the page in a private window.
  4. View the page source and search for part of your code.

If your code appears in the source, the snippet is running and the problem is in the code itself. If it does not appear, return to the activation and location checks.

Our guide on clearing cache in WordPress lists the purge buttons for popular plugins.

Why does a JavaScript snippet not run?

JavaScript snippets fail when they run before the elements or libraries they need exist, when optimisation plugins delay them, or when another script throws an error first.

Open the browser console with F12 and reload the page. Red errors point to the problem.

Common fixes include:

  • Load order. Move the snippet to the footer, or wrap it in a DOMContentLoaded listener.
  • jQuery not ready. If your code uses jQuery, make sure jQuery loads first and use jQuery instead of the dollar sign.
  • Delayed scripts. Plugins that defer or delay JavaScript can stop inline scripts. Exclude your snippet from those features.
  • Earlier errors. A broken script elsewhere can stop scripts after it.

MDN's page on the DOMContentLoaded event explains why waiting for the page matters.

Why does a CSS snippet have no effect?

CSS snippets often lose to more specific theme rules, so check the element in developer tools and raise your selector's specificity rather than reaching straight for important flags.

Right-click the element, choose Inspect, and look at the Styles panel. If your rule is crossed out, another rule wins.

Copy the theme's selector and make yours slightly more specific. Also check the snippet location, as CSS placed only on certain pages will not apply elsewhere.

What if a snippet locked you out of the site?

If a snippet broke the site so you cannot log in, use WPCode's safe mode or disable the plugin by renaming its folder over FTP, then fix the snippet.

WPCode offers a safe mode that loads the site without running snippets, so you can edit the faulty one. Check WPCode's documentation for the exact address to use.

If that is not possible, connect with FTP or your host's file manager and rename the WPCode folder inside wp-content/plugins. The site loads without snippets.

Then log in, rename the folder back, deactivate the broken snippet before it runs again and correct the code. Our guide on troubleshooting WordPress without admin access covers FTP access in detail.

Frequently asked questions

Why does my WPCode snippet keep turning off?

WPCode deactivates a PHP snippet when it causes an error, so the site keeps working. Open the snippet and read the error notice, which usually names the line and cause. Fix the code, save and switch it back on.

Should I include the PHP opening tag in WPCode?

No. For a PHP snippet, WPCode adds the opening tag itself, and pasting another one can cause a syntax error. Start your snippet with the first line of actual code instead.

Why does my tracking code show as text on the page?

The code type probably does not match. Tracking codes copied with their own script tags belong in an HTML snippet. Using a JavaScript snippet adds extra tags, and using a text type prints the code instead of running it.

How do I check if a WPCode snippet is loading?

Open the page in a private window, view the page source and search for a unique part of your code. If you find it, the snippet runs and any problem is in the code. If not, check the status, location and conditional logic.

Can caching stop a WPCode snippet from working?

Yes. Page caches and CDNs can keep serving the old page without your new code. Purge every cache layer after changing a snippet, then test in a private window while logged out.

Sources

  1. WPCode – Insert Headers and Footers + Custom Code Snippets WordPress.org
  2. How to debug PHP errors in WPCode WPCode
  3. Hooks WordPress Developer Resources
  4. Debugging in WordPress WordPress Developer Resources
  5. DOMContentLoaded event MDN Web Docs
  6. PHP manual PHP.net

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

Written and checked byWPLegible Editorial Team Independent WordPress reviews and guides

Researched from the primary sources listed above and checked against our editorial rules before publishing.