• I am developing a site using a child theme of twentyninteen. I have it working as it should but I’m trying to clean it up and make it better.

    A script in the parent twentynineteen theme is causing problems when the site is viewed on ipad. I have tried to dequeue it but it still seems to be loading. The script is in wp-content/themes/twentynineteen/js and is touch-keyboard-navigation.js

    Here is my child theme funtions.php:

    <?php
    //* Code goes here

    function enqueue_parent_styles() {
    wp_enqueue_style( ‘parent-style’, get_template_directory_uri().’/style.css’ );
    }

    add_action( ‘wp_enqueue_scripts’, ‘enqueue_parent_styles’ );

    //Dequeue JavaScripts
    function project_dequeue_unnecessary_scripts() {
    wp_dequeue_script( ‘touch-keyboard-navigation’ );
    }
    add_action( ‘wp_print_scripts’, ‘project_dequeue_unnecessary_scripts’, 100 );

    Any help getting this configured correctly to remove script will be much appreciated. Thanks!

Viewing 6 replies - 31 through 36 (of 36 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Easiest thing you can do is just remove all the code that is inside your child theme touch nav file

    Thread Starter markf1

    (@markf1)

    hmmm. I don’t think I have a child theme touch nav file so….

    My original question remains – how can I dequeue that script?

    Thread Starter markf1

    (@markf1)

    Ok maybe I do understand. leave the script in the child nav js folder, but delete the code inside of it.

    So it would look like this:

    /**
    * Touch & Keyboard navigation.
    *
    * Contains handlers for touch devices and keyboard navigation.
    */

    /**
    * Debounce
    *
    * @param {Function} func
    * @param {number} wait
    * @param {boolean} immediate
    */

    I am not versus ed in javascript. Wold this need an open and closing tag or anything else?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    JS can work without any code at all, it can be entirely empty of code. I’m being terse in my replies because I don’t encourage this approach to future readers.

    Thread Starter markf1

    (@markf1)

    Ok and I am keen to have it working for all users. I understand and support the value and philosophy behind that, but until that script gets fixed I cannot have it in my site.

    thnaks!

    “touch-keyboard-navigation” is the wrong slug.

    On line 226 of functions.php in Twentynineteen:

    wp_enqueue_script( ‘twentynineteen-touch-navigation‘, get_theme_file_uri( ‘/js/touch-keyboard-navigation.js’ ), array(), ‘1.1’, true );

    Understanding that the twentynineteen theme only enqueues touch navigation if there’s a menu assigned to Primary (menu-1), you could unregister this menu and register your own to eliminate touch navigation.

    For sake of simply dequeuing the script outright, in addition to using ‘wp_enqueue_scripts’ instead of ‘wp_print_scripts’, this should work:

    //Dequeue JavaScripts
    function project_dequeue_unnecessary_scripts() {
    wp_dequeue_script( 'twentynineteen-touch-navigation' );
    }
    add_action( ‘wp_enqueue_scripts’, ‘project_dequeue_unnecessary_scripts’, 999 );
Viewing 6 replies - 31 through 36 (of 36 total)
  • The topic ‘dequeue parent theme script in child theme’ is closed to new replies.