Back to Community

Troubleshooting Common Script Insertion Issues with the WPCode Plugin

20 threads Sep 9, 2025 PluginWpcode

Content

If you're using the WPCode plugin (formerly Insert Headers and Footers) to add custom scripts to your WordPress site, you might occasionally run into problems where the code doesn't execute, causes errors, or doesn't appear at all. This guide covers the most frequent issues users encounter and provides step-by-step solutions to get your scripts working correctly.

1. Scripts Not Executing or Displaying as Text

A very common issue is pasting JavaScript code without the proper <script> tags. The plugin offers different code types, and using the wrong one is a typical mistake.

  • Why it happens: The plugin's JavaScript code type expects pure JavaScript without <script> tags. The HTML code type is for any code that includes HTML tags.
  • The fix: If your code snippet already includes <script> tags, you must select the HTML code type. If it is pure JavaScript without tags, use the JavaScript code type.

2. Script is Missing from the Page Source

You've added a script, but when you view your site's source code, it's nowhere to be found.

  • Why it happens: This is often caused by aggressive caching or asset optimization plugins. These tools combine, minify, or delay scripts to improve performance, which can sometimes remove or break them.
  • The fix: Temporarily clear all your site and browser caches. Then, try temporarily disabling any caching, CSS/JS optimization, or CDN settings. If the script appears, you know the optimization plugin is the culprit. You can then reconfigure it to exclude the specific script from optimization.

3. JavaScript Errors Breaking Other Scripts

An error from one script, often visible in the browser's console (F12), can prevent other scripts on the page from running.

  • Why it happens: The script might be trying to access a page element (like document.querySelector(...)) that doesn't exist yet or at all on the page. It could also be a conflict with another script or theme.
  • The fix: Open your browser's developer console (F12) and check for any red error messages. The error will usually point to the problematic line of code. Ensure your script is only loaded on pages where the required elements exist. You can use the plugin's built-in Insert Logic to control where a snippet runs. Also, try loading the script in the footer to ensure the DOM is fully loaded before it executes.

4. Script Works on Desktop But Not Mobile

Your code functions perfectly on a desktop browser but fails to work on mobile devices.

  • Why it happens: This can occur if your site uses a separate mobile cache, a plugin that serves a different mobile version (like AMP), or if there is conditional logic that only runs on mobile.
  • The fix: Check if you have any plugins that create a separate mobile experience or cache. Disable them temporarily to test. Also, use your mobile browser's inspection tools to check for any JavaScript errors that are specific to the mobile view.

5. Incorrect Script Placement

You need a script to load in a very specific location, such as right after the <head> tag, but it appears lower down.

  • Why it happens: The WPCode plugin uses standard WordPress hooks like wp_head to insert code. The exact placement within the <head> section is influenced by the priority set for that hook and what other themes/plugins are doing.
  • The fix: For a snippet, you can edit it and change the Priority number in the Insertion panel. A lower number (e.g., 1) means it will execute earlier and likely be placed higher up. However, note that any elements hardcoded directly in your theme's header.php file will still appear above code inserted via wp_head.

6. jQuery Code Not Working

You've added a jQuery script, but nothing happens.

  • Why it happens: Your script may be trying to run before the jQuery library itself has been loaded onto the page, or jQuery may not be loaded on your site at all.
  • The fix: First, ensure your theme or another plugin loads jQuery. If it doesn't, you will need to enqueue jQuery first. You can do this by creating a separate PHP snippet in WPCode to load it. Secondly, make sure your custom jQuery script is set to load in the Footer to ensure it runs after jQuery is available.

General Troubleshooting Steps

If you're still stuck, follow this general process:

  1. Check the Code Type: Double-check that you've selected the correct code type (HTML or JavaScript) for your snippet.
  2. Disable Caching: Temporarily disable all caching and optimization plugins to rule them out.
  3. Check for Conflicts: Temporarily switch to a default WordPress theme (like Twenty Twenty-Four) and disable all other plugins except WPCode. If the script works, reactivate your theme and plugins one by one to find the conflict.
  4. Inspect the Console: Always use your browser's developer console (F12) to check for JavaScript errors. This is the most valuable tool for diagnosing script problems.

By methodically working through these common issues, you can resolve most problems related to inserting scripts with the WPCode plugin.

Related Support Threads Support