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??

  • What is wrong in calling wp_enqueue_script multiple times with different arguments (links to different scripts) in enqueue_scripts_to_footer ? – Omar Tariq Dec 18 '15 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 Dec 18 '15 at 14:03
0

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' );
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

  • 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 Dec 18 '15 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 Dec 18 '15 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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