Autoptimize is a great plugin for WordPress that combines scripts and code to reduce HTTP look ups. This can speed websites up considerably, improving both visitor experience and how Google, Yahoo, etc rank the site. Using Autoptimize and Contact Form 7 on the same WordPress install however can stop a visitor being able to send a message through the site with a “Failed to Send Your Message” message displayed when hitting the submit button.
Similar to how Recaptcha can interfere with Contact Form 7 submissions, Autoptimize and Contact Form 7 can also cause conflicts. This is due to one of the pieces of code the plugin is able to reduce – Javascript.
When I encountered Autoptimize and Contact Form 7 conflicts on my own site I did a lot of searching and found a solution of adding the selected code to an exclude list…
Unfortunately this did not work for me so I needed to find another solution. This solution was to exclude the contact page from being optimised… Thankfully it’s fairly straightforward and includes adding a piece of code to the functions.php file – a really simple and good way to do this is using a plugin called Code Snippets…
The plugin can be obtained here. Once installed it allows you to add pieces of code to your functions.php file without editing any core files. This is also beneficial as you can continue to update WordPress without any changes being overwritten. It is also easy to manage any snippets that are added.
You’ll need to specify the page ID to be excluded. This can be found by navigating to the page that features your content form whilst in WP-admin – it is shown in the URL bar:
Once you have this, add the following code to Code Snippets – replacing ‘test’ with your page ID.
// Disable autoptimize on pages with the word "test" in the URL
add_filter('autoptimize_filter_noptimize','my_ao_noptimize',10,0);
function my_ao_noptimize() {
if (strpos($_SERVER['REQUEST_URI'],'test')!==false) {
return true;
} else {
return false;
}
}
Once activated, Autoptimize will no longer combine scripts on that page and your Contact Form 7 submissions will work as they should.
At Clook, one of our specialisms is providing WordPress hosting, if you’d like to find out more, please get in touch with us.
Clook Internet is a trading style of Sub 6 Limited. Registered in England and Wales Registration No 4439133 | VAT Registration No 844 7894 73