De-register JS from header to and Re-register JS to footer? (5 posts)

  1. halben
    Posted 2 years ago #

    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,

  2. J M
    Posted 2 years ago #

    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?

  3. halben
    Posted 2 years ago #

    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.

  4. J M
    Posted 2 years ago #

    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.

  5. colbywhitted
    Posted 2 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic