Opens in a new tab

Save $50 Every Year with MainWP

Get $50 off the MainWP Yearly Plan this Black Friday. Your discount renews every year! Claim Your $50 Discount
← Back to blog

Useful Code Snippets for WordPress 6.1

This post may contain affiliate links. Read the disclosure.
Useful Code Snippets WordPress 6.1

WordPress 6.1 is scheduled to be released on the 1st of November and contains many feature improvements.

WordPress 6.1

Database queries made using WP_Query will now be cached by default in WordPress 6.1.

To disable caching globally on query improvements (extreme case), use this code snippet;

function disable_caching( $wp_query ) {
   $wp_query->query_vars['cache_results'] = false;
}

add_action( 'parse_query', 'disable_caching' );

Also, in the WordPress 6.1 release, new cache checks are being added to the site health, and a new filter was added so that you can suggest persistent object caching and change the link in the check for caching in site health.

In the site health report in wp-admin opt-in to suggest object caching;

add_filter( 'site_status_should_suggest_persistent_object_cache', '__return_true' );

To change the WordPress URL link to your link for a client;

add_filter( 'site_status_persistent_object_cache_url', function() {
    return 'https://sitedomain.com/optimization/persistent-object-cache';
} );

To disable new user email notifications to admin users, they can be disabled using the new filter added in WordPress 6.1.

add_filter( 'wp_send_new_user_notification_to_admin', '__return_false' ); 

To modify the lost password link HTML link wording, the new filter can be used in WordPress 6.1.

apply_filters( 'lost_password_html_link', $html_link );

(The WP.org docs will be updated soon for the correct code snippet)

You can insert these code snippets to multiple WordPress sites at once using the MainWP Code Snippet Extension.

Useful Links

Explore MainWP Pro
Get MainWP Pro
Topics: Tips & Tricks