Digital experiences for all disciplines
New Landing › How can we help? › Themeforest Theme Support › Dante › Adding JS to dante child theme
New Landing › How can we help? › Themeforest Theme Support › Dante › Adding JS to dante child theme
- This topic has 13 replies, 5 voices, and was last updated 9 years by David Martin – Support.
-
Posted in: Dante
-
July 4, 2014 at 11:55 am #88074
Hi
New to WP
I have added a child theme to Dante so easier to alter some things and functions.php works fineHowever how do i add a different js file?
Looked on web and got this from codex
(added into \wp-content\themes\dante-child\functions.php)
add_action( ‘wp_print_scripts’, ‘child_overwrite_scripts’, 100 );function child_overwrite_scripts() {
wp_deregister_script( ‘sf-functions’, SF_LOCAL_PATH . ‘/js/functions.js’ );
wp_register_script( ‘sf-functions’, SF_LOCAL_PATH . ‘/js/functions.js’, ‘jquery’, NULL, TRUE );
}the Deregister part works ok but what is wrong with the register code for the child js?
Thanks
July 4, 2014 at 12:19 pm #88096Hi
The easiest way to add custom JS is by adding it to Theme Options > Custom CSS/JS
– Kyle
July 4, 2014 at 12:57 pm #88107Hi Kyle
Thanks for that
However if I do that will it be preserved when I update the theme (and where will it be saved)?Also I actually wanted to change some of the code in an existing function – surely your suggestion will not apply to that?
Specifically at this point I wanted to reduce the padding-top on the page-heading.fancy-heading from 120px to say 50px
When I just changed it in the css stylesheet it was over-ridden by the js in the theme (I think) in the headerOverlaySet: function() { part of the functions.jsThat is what I wish to resolve
Thanks
July 4, 2014 at 1:05 pm #88110Hi
If you want to edit the JS that is already in the theme, you would need to edit the functions.js file, however you can’t add this file to your child theme. For CSS instances, you can override the theme css with !important if need be. In this case you just need to add this to your custom css:
.page-heading.fancy-heading { padding-top: 50px; padding-bottom: 50px; }
Oh, and the theme options > custom css & js will not be overwritten when you update the theme, it is saved in the database
– Kyle
July 4, 2014 at 1:31 pm #88125Hi Kyle
That is what I did initially and as I said in my first email it did NOT work
I then looked at the source code to see why not and saw that the js (presumably) had written in a style for padding-top which was then what was used by the browser (checked in Web Developer)- NOT the value that I had in the css…
Surely it is possible to over-ride js functions using child themes for Dante (as I believe you can with other Themes) else you would need to remember all changes that you had made to effectively core code (I thought that was the point of child themes and why WP had introduced them?)
Cheers
July 4, 2014 at 1:56 pm #88136Try:
.page-heading.fancy-heading { padding-top: 50px!important; padding-bottom: 50px!important; }
That definitely works
– Kyle
July 4, 2014 at 2:18 pm #88146Hi Kyle
Yes the !important makes all the difference!
You didn’t respond to my question about the child theme and js files?
thanks
KeithJuly 4, 2014 at 2:39 pm #88152Will check this with Mohammad, he will be with your shortly
– Kyle
August 18, 2015 at 7:38 am #204788Looking for the same answer.
Namely, I want permanently remove some part of a code from js/functions.js
I think the easiest it would be to overwrite functions.js by adding it to child theme.August 18, 2015 at 8:07 am #204807Hi,
Please create a directory named js at child theme directory. Now place functions.js at /dante-child/js/ and edit it as you want.
Now insert this code at<?php function remove_scripts(){ wp_deregister_script('sf-functions' ); wp_register_script('sf-functions-new', SF_LOCAL_PATH . '/js/functions.js', 'jquery', NULL, TRUE); if (!is_admin()) { wp_enqueue_script('sf-functions'); } } add_action( 'wp_enqueue_scripts', 'remove_scripts', 100 ); ?>
Thanks
MohammadSeptember 10, 2015 at 8:49 pm #212153Hello Mohammad,
Where this code should be placed?
I added it to dante-child/functions.php but this just removes themes/dante/js/functions.js 🙁September 11, 2015 at 6:36 am #212185Hi,
We can only remove the js file. Because override rule dont work with JS files. So i removed the parent functions.js and added new functions.js file.
Thanks
MohammadSeptember 11, 2015 at 7:25 am #212197I see, but problem is that I don’t see dante-child/js/functions.js in a page code. Looks that new functions.js is not added by this function.
September 11, 2015 at 8:58 am #212230Hey,
Looks like a small typo, in the code provided change this
wp_enqueue_script('sf-functions');
to thiswp_enqueue_script('sf-functions-new');
.Thanks,
David. -
Posted in: Dante
You must be logged in and have valid license to reply to this topic.