What You’ll Learn
- Understanding the three code snippet types
- Executing and saving code snippets
- Removing snippets from child sites
- Recovering from bad snippets
- Useful wp-config.php snippets
Extension Add-on - This add-on provides standalone functionality within MainWP Dashboard. No third-party plugins required.
The MainWP Code Snippets Extension is a simple way to add code snippets to your child sites from one centralized location. The code snippet is a small chunk of PHP code inserted directly into your child sites. Sometimes they contain full functions; other times, they modify an existing function.
Code Snippet Types
The MainWP Code Snippet Extension allows you to run code in three ways:Execute a function on the Child site
Execute a function on the Child site
This type of snippet will add the snippet on your child site, and it will be executed on-site load. This type of snippets will be saved in your child site database and executed each time your child site is loaded. You would use this option to make actual changes to your child sites. For example, if you wanted to customize the admin footer across different sites in your network, you would use this option.
Return information from a Child site
Return information from a Child site
This type of snippet will get the info from child sites and display it in the Output Display. This type of snippet will not be saved on your child sites. This option queries the child and returns the information to you. An example would be if you wanted to know the published post count of all of your sites.
Edit the wp-config.php file on a Child site
Edit the wp-config.php file on a Child site
This type of snippets will be added to your child site wp-config.php file and saved only in that file. One of the most important files in your WordPress installation is the wp-config.php file. A Code Snippet in this section allows you to do things such as increase WordPress memory, block external requests, disable WP-Cron, and much more.
Remove a Code Snippet From a Broken Site
Code snippets can be removed directly from the Database. To do this,
This will remove all code snippets that were applied using our Code Snippets extension. If you use bad snippets that are saved to the WP-Config.php, the file will need to be edited manually!
Execute a Code Snippet
Execute a New Code Snippet
Go to the MainWP > Add-ons > Code Snippets > Execute Snippet page
Go to the MainWP > Add-ons > Code Snippets > Execute Snippet page

Select Child Sites where you want to execute the snippet
Select Child Sites where you want to execute the snippet NOTE: A snippet cannot be executed on both the selection of Sites and a selection of Tags. If it is already executed to either Sites or Tags, and you choose the other selection type, it will be removed from the existing selection.
Execute a Saved Code Snippet
Save a Code Snippet
Save a New Code Snippet
Go to the MainWP > Add-ons > Code Snippets > Execute Snippet page
Go to the MainWP > Add-ons > Code Snippets > Execute Snippet page

Select Child Sites where you plan to save the snippet
Select Child Sites where you plan to save the snippet NOTE: A snippet cannot be saved on both the selection of sites and a selection of tags. If it is already saved to either sites or tags, and you choose the other selection type, it will be removed from the existing selection.
Edit a Saved Code Snippet
Remove a Code Snippet From Child Sites
Once the Code Snippet loads, unselect child sites where you want to remove the snippet
Once the Code Snippet loads, unselect child sites where you want to remove the snippet
Useful Code Snippets
MainWP is not responsible for the code that you run on your sites. Use this tool with extreme care and at your own risk. It is recommended that you run any code on a test site before releasing it on live sites. In case you damage your site by using a bad code snippet, read this to see how to fix it.Delete rows in the wp_mainwp_stream_meta and wp_mainwp_stream tables
This can be useful if the wp_mainwp_stream_meta and wp_mainwp_stream tables have grown large in size. To prevent them from growing this large in the future, consider lowering the number of days for which the records are kept. NOTE: This will delete all records in these two tables, which means that the Pro Reports reports will not have any information about events prior to this deletion. When running the script, make sure to select Return info from Child Sites.Change the value of “Keep Records for” in MainWP Child Reports plugin

Disable theme, plugin editor and plugin, core updates
This snippet goes to the wp-config.php file of your child sites. Be sure to select the correct (3rd) option when using the code snippet.Disable CRON job feature
This snippet goes to the wp-config.php file of your site. Be sure to select the correct (3rd) option when using the code snippet.Set auto-save interval
This snippet goes to the wp-config.php file of your site. Be sure to select the correct (3rd) option when using the code snippet.Block external requests
This snippet goes to the wp-config.php file of your site. Be sure to select the correct (3rd) option when using the code snippet.Increase WordPress memory limit
This snippet goes to the wp-config.php file of your site. Be sure to select the correct (3rd) option when using the code snippet.Enable Debug Mode
This snippet goes to the wp-config.php file of your site. Be sure to select the correct (3rd) option when using the code snippet.Disable All Core Updates
This snippet goes to the wp-config.php file of your site. Be sure to select the correct 3rd) option when using the code snippet.Protect WordPress against malicious URL requests
This snippet has to be saved to the functions.php file so be sure to select the “Execute on Child Sites” options when executing the snippet.Related Resources
- Development Add-ons - Browse all development tools
- White Label Extension - Deploy filters to child sites
- Bulk Settings Manager - Manage plugin settings

