New Landing How can we help? Themeforest Theme Support Dante Order of Custom JS File

Viewing 8 posts - 1 through 8 (of 8 total)
  • Posted in: Dante
  • #224846
    absolutnil
    Member
    Post count: 13

    Currently the Custom JS section of the Theme options loads well before the rest of the combined JS files before the ending body tag. Is there a way to have the custom JS load at the very end after the combined JS files? I have scripts that modify the behavior of the certain scripts that needs to fire after it is loaded.

    I currently have my custom js loading via the functions.php of the child theme, and would like to use it if possible, but it too is loading at the top before the other combined js files. I’m no WP expert, is there a way to make my custom js load at the very bottom of the enqueued files?

    Thanks in advance!

    Jay

    #224888
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    What code have been used by you?
    Thanks
    Mohammad

    #225057
    absolutnil
    Member
    Post count: 13

    Hi Mohammad,

    In my child theme’s functions.php I am using this code:

    if ( !is_admin() ) { // instruction to only load if it is not the admin area
       // register your script location, dependencies and version
       wp_register_script(
           'custom-abend-javascript',
            get_stylesheet_directory_uri() . '/custom-abend-javascript.js',
            false,
            '1.0',
            true );
    
       // enqueue the script
       wp_enqueue_script('custom-abend-javascript');
    }

    I also tried this code as well:

    add_action( 'wp_enqueue_scripts', 'child_add_scripts' );
    
    /**
     * Register and enqueue a script that does not depend on a JavaScript library.
     */
    function child_add_scripts() {
        wp_register_script(
            'custom-abend-javascript',
            get_stylesheet_directory_uri() . '/custom-abend-javascript.js',
            false,
            '1.0',
            true
        );
    
        wp_enqueue_script( 'custom-abend-javascript' );
    }

    Thanks!

    #225089
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    Please use the code like this.

    
    add_action( 'wp_enqueue_scripts', 'child_add_scripts' );
    
    /**
     * Register and enqueue a script that does not depend on a JavaScript library.
     */
    function child_add_scripts() {
        wp_register_script(
            'custom-abend-javascript',
            get_stylesheet_directory_uri() . '/custom-abend-javascript.js',
            false,
            '1.0',
            true
        );
    
        wp_enqueue_script( 'custom-abend-javascript','sf-functions-min', NULL, TRUE);
    }

    Thanks
    Mohammad

    #225093
    absolutnil
    Member
    Post count: 13

    Thanks for the code!! I applied it to my child-theme functions.php and it appears to still be at the top of the JS files. See the screenshot for it’s location, highlighted in yellow.

    Attachments:
    You must be logged in to view attached files.
    #225096
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Try to replace the first line of code that my colleague provided you by this one below.

    add_action( 'wp_enqueue_scripts', 'child_add_scripts', 200 );

    Let us know the result.

    -Rui

    #225097
    absolutnil
    Member
    Post count: 13

    You guys are so awesome!!! Thanks so much! That helps me so much!

    Thanks again!!

    #225107
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Great. Glad it’s sorted. Thanks Mohammad.

    -Rui

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register