• Hello !

    Wordpress : 4.6.1
    Theme : Nirvana

    I would like to edit a JS function from my theme. I am using a child of the parent theme, so I assume that the proper way to do this is the edit the file in my child theme. Thing is, I can enqueue my modified script, but no matter what I do, I just cannot remove the “original” JS script using wp_dequeue_script in my functions.php file (from my child theme).

    Here is my functions.php :

    <?php
    function my_theme_enqueue_styles() {
    
        $parent_style = 'parent-style'; // This is 'nirvana-style' for the Nirvana theme.
    
        wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( 'child-style',
            get_stylesheet_directory_uri() . '/style.css',
            array( $parent_style ),
            wp_get_theme()->get('Version')
        );
    }
    
    function project_enqueue_custom_scripts() {
        wp_register_script('cryout-frontend-child', get_stylesheet_directory_uri() . '/js/frontend.js', array('jquery'), 1, true );
        wp_enqueue_script( 'cryout-frontend-child' );
    }
    
    function project_dequeue_cryout_frontend() {
        wp_dequeue_script( 'cryout-frontend' );
    }
    
    add_action( 'wp_print_scripts', 'project_dequeue_cryout_frontend');
    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    add_action( 'wp_enqueue_scripts', 'project_enqueue_custom_scripts' );
    
    ?>

    The original script is cryout-frontend, the one from the child theme is cryout-frontend-child. With this configuration, I have both script being loaded in my index file …

    <script type='text/javascript' src='http://skadi-web.fr/wp-content/plugins/sticky-menu-or-anything-on-scroll/assets/js/stickThis.js?ver=2.0.1'></script>
    <script type='text/javascript' src='http://skadi-web.fr/wp-content/themes/nirvana-child/js/frontend.js?ver=1'></script>
    <script type='text/javascript'>
    /* <![CDATA[ */
    var nirvana_settings = {"mobile":"1","fitvids":"1"};
    /* ]]> */
    </script>
    <script type='text/javascript' src='http://skadi-web.fr/wp-content/themes/nirvana/js/frontend.js?ver=1.3.2'></script>
    <script type='text/javascript' src='http://skadi-web.fr/wp-includes/js/comment-reply.min.js?ver=4.6.1'></script>
    <script type='text/javascript' src='http://skadi-web.fr/wp-includes/js/wp-embed.min.js?ver=4.6.1'></script>
    <script type="text/javascript">var cryout_global_content_width = 810;</script>
    </body>
    </html>

    Any idea about what I can do to dequeue for good the original JS script ? Or another way to replace original script with my own ?

    Thanks in advance for your help ! 🙂

    • This topic was modified 9 years, 6 months ago by SKADI.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Your code looks fine, but i’ve gone through every file of this theme and the only reference I can find to this frontend script is being enqueued using the id nirvana-frontend, I cannot find a reference to cryout-frontend in any file.

    Hope this helps.

    Thread Starter SKADI

    (@skadi)

    Wow, yes indeed it is working, I was doing my search on a former version of theme (just the previous one) and it seems that the name of the reference has changed in the last update …

    Thank you so much !

    And if you still would have some time to help me, I am now facing another issue : on my child theme frontend.js script, I get the error :
    "Uncaught ReferenceError: nirvana_settings is not defined"
    on line 12 :
    if (nirvana_settings['mobile'] == 1) {
    Is this variable defined in another JS file ? If so, why is it missing since other JS files are not replaced ? I am a newbie in JS, I don’t know exactly what I should look for.

    • This reply was modified 9 years, 6 months ago by SKADI.
    • This reply was modified 9 years, 6 months ago by SKADI.

    I’m not the best person to speak to about JS support I’m afraid.

    The parent theme frontend.js file contains a variety of errors according to my IDE, including the one on line 12 where nirvana_settings is not being defined.

    I’m certainly no JS expert though, I’ve done some searching but can only find solutions for vairables not being defined, hopefully someone else can pitch in, or try posting on the Nirvana Theme Support Forum.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘How to replace JS script in child theme ?’ is closed to new replies.