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' );

https://developer.wordpress.org/reference/functions/show_admin_bar/

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;
    $wp_admin_bar->remove_menu('comments');
});

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

Manage all your WordPress sites with the MainWP Dashboard

WordPress Management for Professionals

Are you ready to go Pro?

All MainWP Pro Extensions are available through one of our convenient bundled packages.

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');
     $contributor->add_cap('upload_files');
}

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?

Your Download Is Just One Click Away

…or just download the plugin.

By entering your email, you agree to our Terms of Service and Privacy Policy.