• I’ve got this in my functions.php:

        // Deregister CF7 script and style except where needed
        function mpb_disable_wpcf7() {
          if  ( is_page( '1' ) || is_page( '2' ) || is_page( '3' ) ) { // change these to whatever pages or posts have a form on them
          } else {
            add_filter( 'wpcf7_load_js', '__return_false' );
            add_filter( 'wpcf7_load_css', '__return_false' );
          }
        }
        
        add_action( 'wp_head', 'mpb_disable_wpcf7' );

    I supspect I need to use a different hook to get it to work, since CF7 still loads on all the pages.

Viewing 1 replies (of 1 total)
  • Thread Starter Chris J. Z?hller

    (@seezee)

    Solved it.

        // Deregister CF7 script and style except where needed
        function mpb_disable_wpcf7() {
          if  ( ! is_page( array( 1, 3, 7, 'some-slug', 'Some Post Title' ) ) ) {
          wp_dequeue_style( 'contact-form-7' );
          wp_deregister_style( 'contact-form-7' );
          wp_dequeue_script( 'contact-form-7' );
          wp_deregister_script( 'contact-form-7' );
          }
        }
        
        add_action( 'wp_enqueue_scripts', 'mpb_disable_wpcf7' );
    
    
Viewing 1 replies (of 1 total)
  • The topic ‘Conditionally load JS & CSS without special template’ is closed to new replies.