• Resolved mariohillemann

    (@mariohillemann)


    Hi,

    I am using version 4.5.1 and I already have include require js in my theme in my functions.php by:

    function custom_jquery() {
       if (!is_admin()) {
          	wp_enqueue_script( 'requirejs', get_stylesheet_directory_uri(). '/js/require.min.js', array( 'jquery', 'jquery-migrate' ) );
          wp_enqueue_script('jquery');
          wp_enqueue_script('jquery-migrate');
       }   
    }
    add_action('init', 'custom_jquery');

    Now I’m getting 2 errors:
    scripts.js:14 Uncaught TypeError: this.ajaxForm is not a function(…)$.fn.wpcf7InitForm @... and

    scripts.js:14(anonymous function) @ scripts.js:459i @ jquery.js:2fireWith @ jquery.js:2ready @ jquery.js:2K @ jquery.js:2
    require.min.js:5 Uncaught Error: Mismatched anonymous define()...

    HTML:
    1. jquery
    2. js-migrate
    3. require-js
    4. form.min (cf7)
    5. scripts.js (cf7)

    Is there a way to use require.js in wordpress AND the plugin cf7?

    greetz

Viewing 1 replies (of 1 total)
  • Thread Starter mariohillemann

    (@mariohillemann)

    I found an answer by myself:

    1.

    add_filter( 'wpcf7_load_css', '__return_false' );
    add_filter( 'wpcf7_load_js', '__return_false' );

    2.

    function custom_jquery() {
      if (!is_admin()) {
       	
        wp_enqueue_script('jquery');
        wp_enqueue_script('jquery-migrate');
    
        // IF CF7 IS LOADED
        if (is_page('contact')) {
          wpcf7_enqueue_scripts();
          wp_enqueue_script( 'require-js', get_stylesheet_directory_uri(). '/js/require.min.js', array( 'jquery', 'jquery-migrate','contact-form-7' ) );
        } else {
          wp_enqueue_script( 'require-js', get_stylesheet_directory_uri(). '/js/require.min.js', array( 'jquery', 'jquery-migrate' ) );
        }
      }   
    }
    add_action('wp_enqueue_scripts', 'custom_jquery');

    So there is an dependency for require-js, not for cf7.
    This is not the best solution, for example there is another plugin, wich needs an deps, but if there is one in a projekt, I can add this too like this above…

Viewing 1 replies (of 1 total)

The topic ‘CF7 and require.js’ is closed to new replies.