MainWP Code Snippets Extension
Run, save and remove PHP code snippets on your child sites without editing functions.php on each one.
Write a PHP snippet once and run it on the sites you pick
The MainWP Code Snippets Extension is a Pro MainWP add-on that lets you run, save and remove PHP code snippets on your child sites from one place. Where a small code change used to mean opening each site’s theme functions.php or wp-config.php, you write the snippet once on your MainWP Dashboard, choose the sites, tags or clients it applies to, and run it. A snippet can report back what each site returns, run every time the site loads, or go into wp-config.php, and saved snippets stay in a list for the next run.
Features
The MainWP Code Snippets Extension gives each snippet a type that decides where the code lives and when it runs.
| Feature | What it means for you |
|---|---|
| Three snippet types | Execute on Site saves the snippet in the child site’s database and runs it when the site loads. Return Info runs the snippet on the selected sites and shows what it returns in the Console. Add to wp-config.php writes the snippet to each selected site’s wp-config.php file. |
| Sites, tags or clients | Choose where a snippet applies from the Sites, Tags or Clients tab of the Select Sites panel. Each saved snippet keeps one targeting mode. |
| Saved snippets | Save a snippet on your Dashboard and push it to child sites later. The Snippets tab lists each snippet with its type, target count and when it was last edited. |
| Code editor with syntax check | Write snippets in a CodeMirror 6 editor with code folding, autocompletion, automatic bracket closing, bracket matching, Tab indentation and line wrapping. The PHP syntax is checked before a snippet is saved, run or pushed to child sites, and any error message shows before the code goes anywhere. |
| Console | Follow each run in the Console, with progress counts, a status icon for each site, the output of Return Info snippets, and a Stop Process button. |
| Remove snippets from sites | Unselect sites, tags or clients and run the snippet again to take it off those sites. Clear every target to remove it from all child sites and keep it saved on your Dashboard. |
Requirements
The MainWP Code Snippets Extension is meant for people who write PHP. It goes on your MainWP Dashboard site, and your child sites need nothing extra.
| Item | Requirement |
|---|---|
| License | MainWP Pro |
| MainWP Dashboard | The MainWP Code Snippets Extension installed and activated on your Dashboard site |
| Child sites | Nothing extra to install. Snippets go to the child sites already connected to your Dashboard. |
| Third-party plugins | None |
| Experience | Recommended for experienced PHP coders |
Setup: run, save or remove a snippet
Every task in the MainWP Code Snippets Extension starts from MainWP > Add-ons > Administrative > Code Snippets.
Run a new snippet
- Go to MainWP > Add-ons > Administrative > Code Snippets and open the New Snippet tab.
- Enter a Snippet Title and, if you want, a Snippet Description.
- Choose the snippet type: Execute on Site, Return Info or Add to wp-config.php.
- In Select Sites, choose the Sites, Tags or Clients where the snippet should run.
- Add your code in the code editor and click Run Snippet. The extension saves the snippet, checks the PHP syntax and opens the Console.
Save a snippet and run it later
- Fill in the New Snippet tab the same way and click Save. The snippet stays on your Dashboard until you run it.
- When you want to run it, open the Snippets tab and click the snippet title or the green action button.
- Check the snippet type and the selected Sites, Tags or Clients, then click Run Snippet.
Remove a snippet from child sites
- Open the snippet from the Snippets tab.
- Unselect the sites, tags or clients you want to remove it from. To remove it from every site, clear all targets.
- Click Run Snippet. The extension removes the saved copy from child sites and adds it back to the targets that are still selected.
Full instructions, example snippets and the recovery steps: MainWP Code Snippets Extension documentation.
Where each snippet type ends up
The MainWP Code Snippets Extension keeps your saved snippets on your MainWP Dashboard and sends a snippet to the child sites you selected when you click Run Snippet. Execute on Site snippets are stored in each child site’s database and run when the site loads, Add to wp-config.php snippets are written to the site’s wp-config.php file, and Return Info snippets send their output back to the Console.
Code Snippets FAQ
Can I add code to my child sites without editing functions.php?
Yes, the MainWP Code Snippets Extension adds code through the Execute on Site snippet type, which saves the snippet in each selected child site’s database and runs it when the site loads. The docs give customizing the admin footer across your sites as an example.
Can I change wp-config.php settings on my child sites?
Yes, the Add to wp-config.php snippet type in the MainWP Code Snippets Extension writes the snippet to the wp-config.php file of each selected child site. The docs include ready-made snippets for constants such as WP_MEMORY_LIMIT, DISABLE_WP_CRON, WP_HTTP_BLOCK_EXTERNAL and DISALLOW_FILE_EDIT.
Do I need to know PHP?
MainWP recommends the Code Snippets Extension for experienced PHP coders. You are responsible for the code you run on your sites, so try each snippet on a test site before you use it on live sites.
How do I remove a snippet from a site by hand?
To remove snippets that the MainWP Code Snippets Extension saved in a child site’s database, open the database in phpMyAdmin, open the options table (wp_options by default; your prefix may differ), and delete the mainwp_ext_snippets_enabled or mainwp_ext_code_snippets row. That removes every database-saved snippet the extension added. For a snippet saved to wp-config.php, edit that file and take the snippet out.





