0

i know how i can print a single script with wp_dequeue_script and wp_enqueue_script to the footer:

function dequeue_my_scripts() {
 wp_dequeue_script('dgx_donate_paypalstd_script');
}
add_action( 'wp_print_scripts', 'dequeue_my_scripts', 11 );

function enqueue_scripts_to_footer() {
   wp_enqueue_script('dgx_donate_paypalstd_script');
}
add_action( 'wp_footer', 'enqueue_scripts_to_footer' );

But how can i print a couple of scripts to the footer. Is there a posibility to use enumeration for example:

function dequeue_my_scripts() {
 wp_dequeue_script('dgx_donate_paypalstd_script','next-handle-script',        'next-handle-script'.....);
}
add_action( 'wp_print_scripts', 'dequeue_my_scripts', 11 );

function enqueue_scripts_to_footer() {
   wp_enqueue_script('dgx_donate_paypalstd_script','next-handle-script',     'next-handle-script'.....);
}
add_action( 'wp_footer', 'enqueue_scripts_to_footer' );

Or is there another possibility??

2
  • What is wrong in calling wp_enqueue_script multiple times with different arguments (links to different scripts) in enqueue_scripts_to_footer ?
    – Omar Tariq
    Commented Dec 18, 2015 at 13:55
  • ok, so i can use: function enqueue_scripts_to_footer() { wp_enqueue_script('onother-script'); } add_action( 'wp_footer', 'enqueue_scripts_to_footer' ); But i have to change the function name: enqueue_scripts_to_footer() right? or can i use the name two times?
    – tom84
    Commented Dec 18, 2015 at 14:03

2 Answers 2

2

Like this:-

function dequeue_my_scripts() {
   wp_dequeue_script('dgx_donate_paypalstd_script');
   wp_dequeue_script('next-handle-script');
   wp_dequeue_script('next-handle-script-2');
   /* and so on*/
}
add_action( 'wp_print_scripts', 'dequeue_my_scripts', 11 );

function enqueue_scripts_to_footer() {
   wp_enqueue_script('dgx_donate_paypalstd_script');
   wp_enqueue_script('next-handle-script');
   wp_enqueue_script('next-handle-script-2');
   /* and so on */
}
add_action( 'wp_footer', 'enqueue_scripts_to_footer' );

What's wrong in this implementation?

EDIT:

I would also like to notify you that this is the correct implementation of what you are trying to achieve:-

function enqueue_scripts_to_footer() {
   wp_enqueue_script('dgx_donate_paypalstd_script', false, array(), false, true);
   wp_enqueue_script('next-handle-script', false, array(), false, true);
   wp_enqueue_script('next-handle-script-2', false, array(), false, true);
   /* and so on */
}
add_action( 'wp_enqueue_scripts', 'enqueue_scripts_to_footer' );
1
  • Little addendum: for the 4th {version number} parameter, it can take false and null as well. Don't know which is better or more elegant. Or if it's there any difference. I use null, but false seems legit as well. Anyone opinion, pro-s ,con-s on this? Commented Sep 8, 2021 at 12:30
0

Right out of the codex: the fifth argument to the wp_enqueue_script function call is a boolean to tell it whether or not to put the script in the footer:

https://codex.wordpress.org/Function_Reference/wp_enqueue_script

2
  • yeah i know the boolean..but what is with my example above. Can i use more than one Handler for the function wp_dequeue_script?
    – tom84
    Commented Dec 18, 2015 at 13:54
  • That's not the question you asked. And no, the call to wp_dequeue_script expects a string. Put your calls to it in a foreach loop if you want to dequeue multiple handles...
    – C C
    Commented Dec 18, 2015 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.