Useful WordPress Code Snippets for your Child Site

WordPress contains a huge number of filters in its core and knowing which filters to use will allow you to be able to make a number of changes on your child sites without having to use any plugins for those changes.

MainWP offers a very solid extension to be able to save and execute useful code snippets to all of your connected child sites. In order to be able to use the code snippets then follow the docs, on how to save then execute the specific code snippet that you want to run. You can always disable code snippets when not needed as well.

Hide the admin bar for all users on the front-end of the site then you can use this code snippet.

add_filter( 'show_admin_bar', '__return_false' );

Remove the comments icon in the admin bar then use the following code snippet.

add_action('wp_before_admin_bar_render', function() {
    global $wp_admin_bar;

If you need to allow contributor users on your child site to be able to upload images then use this code snippet.

if ( current_user_can('contributor') && !current_user_can('upload_files') )
add_action('admin_init', 'allow_contributor_uploads');

function allow_contributor_uploads() {
     $contributor = get_role('contributor');

If you have enabled comments on your site to remove auto-links being created from links added into comments then you can use this code snippet on the site.

remove_filter( 'comment_text', 'make_clickable', 9 );

To change the pulse rate in the Heartbeat API to every 60 seconds you can use this code snippet.

function wpmp_heartbeat_settings( $settings ) {
    $settings['interval'] = 60; //Anything between 15-120
    return $settings;
add_filter( 'heartbeat_settings', 'wpmp_heartbeat_settings' );

MainWP makes it very easy to extend out WordPress by using the code snippets extension to make changes on your connected child sites without having to add extra bloat with extra plugins in the active plugin stack.

Looking for something?

Privacy laws apply to businesses that collect personal information. Since no personal information is collected by the MainWP plugins, no privacy laws apply to the MainWP plugins. This includes GDPR, UK DPA 2018, PIPEDA, Australia Privacy Act 1988, LGPD, PIPL, and other privacy laws.
Donata Stroink-Skillrud
Donata Stroink-Skillrud
President of Agency Attorneys