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
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
Return information from a Child site
Return information from a Child site
Edit the wp-config.php file on a Child site
Edit the wp-config.php file on a Child site
Remove a Code Snippet From a Broken Site
Code snippets can be removed directly from the Database. To do this,Login in to your cPanel, locate the phpMyAdmin, and open your site database
Locate and open the wp_options table
Locate and remove the optionname = mainwpextsnippetse
Execute a Code Snippet
Execute a New Code Snippet
Login in to your MainWP Dashboard
Go to the MainWP > Extensions > Code Snippets > Execute Snippet page

Enter a Snippet Title
Enter a Snippet Description (optional)
Select the snippet type
Select Child Sites where you want to execute the snippet
Add your Code Snippet in the code editor

Click the Save & Execute Snippet button
Execute a Saved Code Snippet
Login in to your MainWP Dashboard
Go to the MainWP > Extensions > Code Snippets > Saved Snippets page
Locate the Code Snippet that you want to execute
Click the Load button

Once the Code Snippet loads, click the Save & Execute Snippet button
Save a Code Snippet
Save a New Code Snippet
Login in to your MainWP Dashboard
Go to the MainWP > Extensions > Code Snippets > Execute Snippet page

Enter a Snippet Title
Enter a Snippet Description (optional)
Select the snippet type
Select Child Sites where you plan to save the snippet
Add your Code Snippet in the code editor

Click the Save Snippet button
Edit a Saved Code Snippet
Login in to your MainWP Dashboard
Go to the MainWP > Extensions > Code Snippets > Saved Snippets page
Locate the Code Snippet that you want to edit
Click the Load button

Once the Code Snippet loads, edit wanted details
Click the Save Snippet button
Remove a Code Snippet From Child Sites
Login in to your MainWP Dashboard
Go to the MainWP > Extensions > Code Snippets > Saved Snippets page
Locate the Code Snippet that you want to remove from your child sites
Click the Load button
Once the Code Snippet loads, unselect child sites where you want to remove the snippet
Click the Save & Execute Snippet button.
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