Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #670264

    hi,

    i registered a .js file with the following code in the functions.php

    function wpdocs_scripts_method() {
        wp_enqueue_script(
            'j-js',
            get_stylesheet_directory_uri() . '/js/j-js.js',
            array('jquery'), $in_footer = true
        );
    
    } 

    But i want to register the script in the footer. How can i do this?

    best regards

    Chris

    #670267

    i think it might work in this way because they go to footer by default? :

    edit: sorry i test it first in a test page

    • This reply was modified 7 years, 7 months ago by Guenni007.
    #670275

    hi guenni007,

    thanks for your answer. with your code i got a php error:

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘wpdocs_scripts_method()’ not found or invalid function name in /wp-includes/plugin.php on line 525

    #670285

    i guess they have here a function on it:

    function include_custom_js_file() {
       wp_enqueue_script( 'avia-main-child', get_stylesheet_directory_uri().'/js/j-js.js', array('jquery', 'avia-default'), 2, true );
    }
    add_action( 'wp_enqueue_scripts', 'include_custom_js_file', 100 );

    and the last true is for footer !

    don’t know if this works as well:

    function wpdocs_scripts_method() {
        wp_enqueue_script( 'avia-main-child', get_stylesheet_directory_uri().'/js/j-js.js', array('jquery', 'avia-default'), 2, true );
    }
    add_action( 'wp_enqueue_scripts', 'wpdocs_scripts_method', 100 );
    • This reply was modified 7 years, 7 months ago by Guenni007.
    #670297

    that works fine :-) thankyou! Is it possible to register 2 or more .js files with this function?

    #670305

    yes – but i don’t know if this here:

    function include_custom_js_file() {
       wp_enqueue_script( 'avia-main-child', get_stylesheet_directory_uri().'/js/custom1.js', array('jquery', 'avia-default'), 2, true );
       wp_enqueue_script( 'avia-main-child', get_stylesheet_directory_uri().'/js/custom2.js', array('jquery', 'avia-default'), 2, true );
       wp_enqueue_script( 'avia-main-child', get_stylesheet_directory_uri().'/js/custom3.js', array('jquery', 'avia-default'), 2, true );
    }
    add_action( 'wp_enqueue_scripts', 'include_custom_js_file', 100 );

    will work – or if you have to make each external js file has to be handled seperately.

    #670660

    Hi,

    Thanks for helping out @Guenni007, did you solve your problem @Chris_85?

    Regards,
    Rikard

    #671865

    yes, thanks

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘register a script in the functions php’ is closed to new replies.