Back to Community

How to Dequeue Akismet's JavaScript for Better Site Performance

28 threads Sep 7, 2025 PluginAkismet anti-spam: spam protection

Content

If you're looking to optimize your WordPress site's performance, you might have noticed the Akismet plugin loading its JavaScript file (akismet/_inc/form.js) on pages where it's not strictly necessary. This is a common concern for site owners focused on speed and efficiency. This guide explains why this happens and provides a straightforward solution to control when the script loads.

Why Does Akismet Load JavaScript?

The Akismet Anti-spam: Spam Protection plugin enqueues its script, registered as akismet-form, to enhance its spam-checking capabilities, particularly for comment forms. The script is typically loaded via hooks like comment_form, wp_footer, admin_footer, admin_head-edit-comments.php. While useful, this can sometimes add an unnecessary HTTP request on pages where no comment form exists, such as a homepage or a contact page that uses a different form plugin.

The Solution: Dequeue the Script

You can prevent the Akismet script from loading on specific pages by using a standard WordPress function, wp_dequeue_script(). This method is safe and will not break the plugin's core functionality; it simply removes the script from the page source.

Here is the most effective code snippet, derived from successful community solutions:

add_action( 'wp_footer', 'dequeue_akismet_js', 1 );
function dequeue_akismet_js() {
    if ( ! is_singular() ) {
        wp_dequeue_script( 'akismet-form' );
    }
}

How it works: This code hooks into the wp_footer action with a high priority (1), which runs early. It then checks if the current page is not a singular post or page (! is_singular()). If it isn't (e.g., it's an archive page, the homepage, etc.), it dequeues the 'akismet-form' script. You can customize the conditional check (is_singular()) to target different pages, like is_front_page() or is_page('contact').

Where to Add the Code

Add this code to your child theme's functions.php file. Using a child theme is crucial to prevent your changes from being overwritten during theme updates. If you are not using a child theme, consider using a code snippets plugin as an alternative.

Important Considerations

  • Testing: After implementing this change, clear your site's cache (if using a caching plugin) and test your comment forms to ensure they still work correctly. The Akismet spam-checking on form submission happens via a separate, server-side process and is not affected by removing this frontend script.
  • Other Hooks: If you find the script is still loading, it might be using a different hook. The primary hook for the frontend is wp_footer, but for admin pages, you might need to use admin_footer.

By taking control of which pages load the Akismet script, you can streamline your site's asset delivery and improve overall loading times without sacrificing functionality.

Related Support Threads Support