Back to Community

Understanding and Troubleshooting Code Snippets in WordPress Multisite

22 threads Sep 7, 2025 PluginCode snippets

Content

Managing code snippets across a WordPress Multisite network can be incredibly powerful, but it sometimes introduces unique challenges. This guide covers the most common issues users face and provides clear solutions based on community experience.

Common Multisite Issues and Their Solutions

1. Snippet Execution Order (Network vs. Site-Specific)

Problem: Network-activated snippets run after site-specific snippets, even if they have a lower priority number. This can break functionality if a site-specific snippet tries to use a class defined in a network snippet.

Solution: This is the intended behavior. To ensure a network snippet runs first, you must use the 'Shared Network' mode. When creating a network-level snippet, uncheck the option 'Allow this snippet to be activated on individual sites on the network'. This will make the snippet run automatically on all sites before any site-specific snippets.

2. Missing Admin Menu for Site Administrators

Problem: Site administrators on individual subsites cannot see the Code Snippets menu, even though the plugin is network-activated.

Solution: The 'Snippets' admin menu is controlled by a network-wide setting.

  1. Go to Network Admin → Settings → Network Settings.
  2. In the 'Enable administration menus' section, ensure the checkbox for 'Snippets' is checked.
  3. Save the settings. Site admins should now have access.

3. The "Allow on Individual Sites" Option Doesn't Save or Work

Problem: The 'Allow this snippet to be activated on individual sites on the network' checkbox does not stay checked when saving a network snippet, or activating it returns a '500' or '400' error.

Solution: This was a known bug in older versions of the plugin. The Code Snippets team has stated that this issue was resolved in version 3.6.6. If you are experiencing this problem, the first step is to update the plugin to the latest version. If the problem persists after updating, try clearing any server or object caching on your site.

4. Snippets Not Copied to a Newly Created or Cloned Subsites

Problem: When a new subsite is created (manually or via a cloning plugin), shared network snippets are not automatically active on it.

Solution: By default, network snippets must be manually activated on new subsites. However, you can automate this with a custom PHP snippet. Use the wp_initialize_site action hook to programmatically activate specific network snippets by their ID whenever a new site is created.

add_action( 'wp_initialize_site', function () {
    update_option( 'active_shared_network_snippets', array( 42, 152, 68 ) );
} );

Replace the numbers in the array (42, 152, 68) with the actual IDs of the snippets you want to be active by default.

5. Cannot Edit or Create Network Snippets

Problem: In the network admin, you are unable to save edits to a snippet, create new ones, or use functions like 'Clone'. The page may refresh without saving changes or show an error.

Solution: This has been linked to specific plugin versions (e.g., v2.14.0). The recommended action is to:

  1. Ensure you are running the latest version of the Code Snippets plugin.
  2. If the problem started immediately after an update, temporarily downgrading to a previous stable version may be a workaround while waiting for a patch. Always back up your site before attempting this.
  3. As a last resort, snippets can be edited directly in the database table wp_ms_snippets, but this is only advised for advanced users.

Key Multisite Concepts

  • Network Snippets: Created in the Network Admin dashboard. They have two modes:
    • Run Everywhere: Snippet runs on all sites automatically (option is unchecked).
    • Shared Network: Snippet appears in the list on every subsite where it can be activated individually (option is checked).
  • Site-Specific Snippets: Created and managed on individual subsites. They only run on that specific site.

By understanding these common pitfalls and their solutions, you can effectively harness the power of the Code Snippets plugin to manage code across your entire WordPress Multisite network.

Related Support Threads Support