-
AuthorPosts
-
August 9, 2016 at 11:46 am #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
August 9, 2016 at 12:05 pm #670267i 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 8 years, 3 months ago by Guenni007.
August 9, 2016 at 12:32 pm #670275hi 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
August 9, 2016 at 12:40 pm #670285i 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 8 years, 3 months ago by Guenni007.
August 9, 2016 at 1:00 pm #670297that works fine :-) thankyou! Is it possible to register 2 or more .js files with this function?
August 9, 2016 at 1:07 pm #670305yes – 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.
August 10, 2016 at 7:29 am #670660August 12, 2016 at 3:50 pm #671865yes, thanks
-
AuthorPosts
- The topic ‘register a script in the functions php’ is closed to new replies.