Load Contact Form 7 only when needed


/ Published in: PHP
Save to your folder(s)

Prevents WordPress from loading Contact Form 7 on page templates other than the one defined.


Copy this code and paste it in your HTML
  1. add_action ('wp_print_scripts', 'my_deregister_cform', 100);
  2.  
  3. function my_deregister_cform() {
  4.  
  5. if (!is_page_template('page-contact.php')) {
  6.  
  7. wp_deregister_script('contact-form-7');
  8.  
  9. }
  10.  
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.