How to replace JS script in child theme ?
-
Hello !
Wordpress : 4.6.1
Theme : NirvanaI 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 ! 🙂
The topic ‘How to replace JS script in child theme ?’ is closed to new replies.