Support » Fixing WordPress » De-register JS from header to and Re-register JS to footer?

  • Before I begin the process, as stated in the title, I want some opinions.

    I need to move the JS files from the header and placed it to the bottom. What I was thinking of was De-registering all the JS files and Enqueue it in the child’s function.php.

    That’s the only solution I could think of at the moment. If anyone has a better solution, please share.

    Thanks for coming,
    Halben

Viewing 4 replies - 1 through 4 (of 4 total)
  • J M

    (@hiphopinenglish)

    If they are already registered using wp_enqueue_script, can’t you move them to the footer using the $in_footer variable in wp_register_script?

    Thread Starter halben

    (@halben)

    I apologize I forgot to mention those JS files are from the plugins I have on the website; I don’t want to edit them in the plugin files.

    J M

    (@hiphopinenglish)

    OK, then your solution seems reasonable. I’m not qualified to comment if there would be any performance issues in deregistering and then re-enqueuing or not.

    I’m working on this as well, using the same solution you mentioned. But I’m having some problems.

    `add_action( 'wp_print_scripts', 'deregister_javascript', 50 );

    function deregister_javascript() {
    wp_deregister_script( 'jquery' );
    }

    add_action( 'wp_enqueue_scripts', 'my_register_scripts', 100 );

    function my_register_scripts() {
    $jquery = "http://domain.com/wp-includes/js/jquery/jquery.js";
    wp_enqueue_script( 'jquery', $jquery, array(), false, true );
    }`

    The above code is not working though. I thought maybe it’s because the hook used for the deregistering is executed after the hook used to add the script. But even if I change the hooks to both wp_print_scripts the scripts appear, but for some reason they do not appear in the footer.
    What am I doing wrong?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘De-register JS from header to and Re-register JS to footer?’ is closed to new replies.