Hello @imbecillen,
We put the lightgallery jQuery library in assets/js/plugins.js file so you can not use deregister function to remove it.
You need to open that file and remove manually.
Thanks a lot @famethemes!
So if I use a child theme, how do I make the child ignore the parent? Just copy the pathway, files and erease the code doesn’t seem to work at least.
Do I need to make a remove_action or something? Thanks a lot for your answer!
Hi @imbecillen,
You can disable the file assets/js/plugins.js from child theme:
https://codex.ww.wp.xz.cn/Function_Reference/wp_deregister_script
then copy that file from the main theme to the child theme, and enqueue it:
https://developer.ww.wp.xz.cn/reference/functions/wp_enqueue_script/#comment-276
Hope it helps!
@famethemes
Okey, I tried but it didn’t work as intended. It may be that I’m doing something wrong so I post my edits here.
In the function.php for the child theme I write the code down under in the end of the file. I also copy the plugin.js file and directory path over to the child theme, as well as ereasing the lightgallery code part from the file so it can’t be read from the new file. Is it correct? Do I need to type in the priority order for the action to appear maybe? If so, which priority should I have?
Thanks a lot for your support!
/**
* Custom code
* Turn off default lightgallery.
* /assets/js/plugins.js
*/
function remove_scripts() {
//----- JS
wp_dequeue_script( 'plugins' );
wp_deregister_script('plugins');
}
add_action('wp_print_scripts', 'remove_scripts');
/**
* Custom code
* Enqueue a script with jQuery as a dependency.
* Get plugin.js from childtheme instead.
*/
function wpdocs_scripts_method() {
wp_enqueue_script( 'plugins', get_stylesheet_directory_uri() . '/assets/js/plugins.js', array( 'jquery' ) );
}
add_action( 'wp_enqueue_scripts', 'wpdocs_scripts_method');
Hi @imbecillen,
Yes. You did wrong because the handle name is onepress-js-plugins, NOT plugins.
So your code should be changed:
function remove_scripts() {
wp_dequeue_script( 'onepress-js-plugins' );
wp_deregister_script('onepress-js-plugins');
}
add_action('wp_print_scripts', 'remove_scripts');
function wpdocs_scripts_method() {
wp_enqueue_script( 'onepress-child-js-plugins', get_stylesheet_directory_uri() . '/assets/js/plugins.js', array( 'jquery' ) );
}
add_action( 'wp_enqueue_scripts', 'wpdocs_scripts_method');
Let me know!
-
This reply was modified 7 years, 9 months ago by
FameThemes.
@famethemes
It works like a charm!!
Thank you so much for the great support and for your wonderful theme 🙂