Advertisement
digital-workshop

Load Contact Form 7 only on Contact Page

Nov 6th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1. /*This goes in wp-config.php*/
  2.  
  3. define('WPCF7_LOAD_JS', false); // Remove CF7 JavaScript
  4. define('WPCF7_LOAD_CSS', false); // Remove CF7 CSS
  5.  
  6. /*This goes in function.php*/
  7.  
  8. /* Contact Form 7 nur auf Kontakt Seite laden */
  9. add_filter( 'wpcf7_load_js', '__return_false' ); // Disable CF7 JavaScript
  10. add_filter( 'wpcf7_load_css', '__return_false' ); // Disable CF7 CSS
  11.  
  12. add_action('wp_enqueue_scripts', 'load_wpcf7_scripts');
  13. function load_wpcf7_scripts() {
  14.     if ( is_page('contact') ) {
  15.         if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
  16.             wpcf7_enqueue_scripts();
  17.         }
  18.         if ( function_exists( 'wpcf7_enqueue_styles' ) ) {
  19.             wpcf7_enqueue_styles();
  20.         }
  21.     }
  22. }
  23.  
  24. /*
  25. Tip
  26. You can also using page ID and even page name instead of page
  27. slug as the condition to match the page.
  28. Refer to is_page() documentation for possible usage.
  29.  
  30. Note
  31. If you have multiple pages with CF7’s contact forms, you can use PHP or operator, ||,
  32. or use the array for is_page() function as the condition. For example:
  33.  
  34. is_page( array( ‘contact’ , ‘feedback’ , ‘survey’ ) )*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement