Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1057997

    Until recent updates, I’ve had a custom avia.js loaded from the child theme. Now doing this throws an error in the JS console, breaking all other site scripts.

    avia.js?ver=5.0.3:536 Uncaught TypeError: $.avia_utilities.supports is not a function
        at avia_hover_effect (avia.js?ver=5.0.3:536)
        at Object.$.avia_utilities.avia_ajax_call (avia.js?ver=5.0.3:85)

    I’ve modified my child theme to use an IDENTICAL copy of the latest version of avia.js just to make sure it wasn’t any of my customization that broke it. If I disable the enfold copy so it doesn’t load and just load it from the child theme, I get the error. But if you load avia.js from enfold it works fine.

    Again, avia.js file is currently identical between enfold and child theme. But loading it from child theme produces this error.

    #1058015

    Hey pippylu,
    I tried to recreate your situation by adding avia.js to my child theme on my localhost, I placed the file at:
    /enfold-child/js/avia.js
    and used the function in my functions.php:

    function wp_change_aviajs() {
    	wp_dequeue_script( 'avia-default' );
    	wp_enqueue_script( 'avia-default-child', get_stylesheet_directory_uri().'/js/avia.js', array('jquery'), 2, true );
    	}
    	add_action( 'wp_print_scripts', 'wp_change_aviajs', 100 );

    the file loaded with no errors.
    Is this the same function you are using?

    Best regards,
    Mike

    #1058269

    Not quite, I am using ‘wp_enqueue_scripts’ action with ‘wp_deregister_script’. Your method makes both copies of avia.js load on the page. I do not want the enfold copy to load, just the child theme copy.

    #1058445

    Hi,
    wp_dequeue_script removes the theme js before wp_enqueue_script adds the child theme js.
    What is the function you are using, I would like to test it.

    Best regards,
    Mike

    #1058950

    When I use wp_dequeue_script the site still loads enfold/js/avia.js.
    Here is what I have right now:

    function vmc_scripts() {
        wp_deregister_script( 'avia-default' );
        wp_enqueue_script( 'avia-default-child', get_stylesheet_directory_uri().'/scripts/avia.js', array('jquery'), false, true );
    }
    add_action( 'wp_enqueue_scripts', 'vmc_scripts', 100 );
    #1059013

    Hi,
    The only way to dequeue a script is that it was enqueue first, but you also need to hook into wp_print_scripts so that it is loaded last, after the script was enqueued. You are hooking into wp_enqueue_scripts
    So you are right, it is loading both, but then dequeue the theme one and running the custom one.
    Typically people have a problem getting their custom avia.js to work, until we recommend this function, please see the links to the Codex.
    I search and found a different solution for you, please see if this is satisfactory
    Here is a technical answer from the dev team.

    Best regards,
    Mike

    #1059205

    I am not following, this code still loads enfold/js/avia.js onto the page. I do not want that script loading. MY copy of avia.js loading last was never the problem. The problem is that enfold’s avia.js is loading at all. I cannot have BOTH scripts on the page at the same time. Mine is meant to be a replacement, not sitting on top of it.

    #1060221

    Hi,

    can u please share us admin details?

    Best regards,
    Basilis

    #1060322

    Here you go

    #1060656

    Hi,
    Sorry for the late reply, I have found how to load only the child theme avia.js
    First in sure that your file is at: /enfold-child/js/avia.js
    Then add this code to the end of your child theme functions.php file in Appearance > Editor:

    
    //Load child theme avia.js
    function wp_change_aviajs() {
    	wp_dequeue_script( 'avia-default', $template_url.'/js/avia.js', array('jquery'));
    	wp_deregister_script(  'avia-default', $template_url.'/js/avia.js', array('jquery'));
    	wp_enqueue_script( 'avia-default', get_stylesheet_directory_uri().'/js/avia.js', array('jquery'));
    	
    	}
    	add_action( 'wp_enqueue_scripts', 'wp_change_aviajs', 100 );
    		

    Best regards,
    Mike

    #1060668

    Thank you very much! That was the solution I needed.
    For anyone else following allowing, the code above works except that $template_url is not defined so I replaced those with get_template_directory(), so the code would be:

    
    //Load child theme avia.js
    function wp_change_aviajs() {
    	wp_dequeue_script( 'avia-default', get_template_directory().'/js/avia.js', array('jquery'));
    	wp_deregister_script(  'avia-default', get_template_directory().'/js/avia.js', array('jquery'));
    	wp_enqueue_script( 'avia-default', get_stylesheet_directory_uri().'/js/avia.js', array('jquery'));
    	
    	}
    	add_action( 'wp_enqueue_scripts', 'wp_change_aviajs', 100 );
    		

    My avia.js file is loaded and the enfold one is not anymore and there are no longer any JS console errors.

    • This reply was modified 5 years, 9 months ago by christiemade.
    #1060674

    Hi,
    That’s odd that $template_url didn’t work for you, because I tested it before I posted it, but I’m glad that you were able to adjust it. What is important is that it’s working for you :)
    Unless there is anything else we can assist with on this issue, shall we close this then?

    Best regards,
    Mike

    #1314881

    This can be closed!

    #1314976

    Hi,

    If you need additional help with this topic please let us know here in the forums.

    Best regards,
    Jordan Shannon

Viewing 14 posts - 1 through 14 (of 14 total)
  • The topic ‘Custom avia.js in child theme’ is closed to new replies.