0

Adding in the child theme a CSS file with the same name as the parent theme CSS file overrides the parent file. It doesn't seem to work JavaScript files.

How can I override a JavaScript file loaded from the parent theme?

  • 1
    Have you tried to replace it using hook_js_alter api.drupal.org/api/drupal/… – berramou Nov 21 at 14:21
  • cannot find the js from parent theme when printing $javascript ? (using the D7 hook) – Matoeil Nov 21 at 14:49
  • Did you try examples from api.drupal.org/api/drupal/modules%21system%21system.api.php/…, are you using advagg module or other module for js aggregation ?. – berramou Nov 21 at 14:52
  • 1
    Generally you don't want to replace a JS file completely because it's very unlikely that you will want to change everything it does. Can you explain why you want to get rid of this one? – Alfred Armstrong Nov 21 at 14:52
  • 1
    and if the js file contain behavior, you should override the behavior with the same name in your child theme . – berramou Nov 21 at 14:59
1

You can use hook_js_alter to replace your JS file (from parent theme) with the one in your child theme.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.