-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding custom JavaScript files for global and specific pages - best practices #96
Comments
Hi, I would enqueue the new Library in the "enqueue-scripts.php" (i.e. you can define jQuery as dependency) and add your custom JavaScript in the "scripts.js" or add a new "*.js" file in the same folder. Gulp should grab it and output it to the "scripts.js". About "page specific" JavaScript I cant really suggest a best practice, still you can find a possibility in The roots / sage theme Best, |
@pablopaul nailed it. 👍 You can enqueue the files in assets/functions/enqueue-scripts.php. Or if you're using Gulp, you can add the scripts to the assets/js/site directory and they will be automatically compiled into the minified JS file. If you want to load specific scripts only on certain pages, check this out: http://mekshq.com/include-javascriptonly-on-specific-wordpress-page-templates/ |
Thanks for the help @pablopaul and @JeremyEnglert One small question regarding /functions/enqueue and adding scripts to the assets/js/site directory: Best regards, |
Hi again I can't seem to get .js-files added correctly when added to the /js/site directory. For example: This is the code: + ");$('.menu-item-has-children').append(" - ");$('.open').addClass('visible'); $('.open-menu-link').click(function(e) { var childMenu = e.currentTarget.parentNode.children[1]; if ($(childMenu).hasClass('visible')) { $(childMenu).removeClass("visible"); $(e.currentTarget.parentNode.children[3]).removeClass("visible"); $(e.currentTarget.parentNode.children[2]).addClass("visible"); } else { $(childMenu).addClass("visible"); $(e.currentTarget.parentNode.children[2]).removeClass("visible"); $(e.currentTarget.parentNode.children[3]).addClass("visible"); } }); $('.menu-btn').click(function() { $('.responsive-menu').toggleClass('expand') }); }); I put this code in: menu.js. Then added it to the assets/js/site directory. But the function is not loaded on the pages. How do I know that the gulp file is processing the files in the assets/js/site properly? Best regards, |
@konsulenten, are you also running the Gulp commands to compile the JS? You can learn more about those here: http://jointswp.com/docs/gulp/ Also, if you don't want to use Gulp, you can add the files directly to your minified scripts. (This is how I did it when I used CodeKit). |
Hi again @JeremyEnglert I was confused by the gulp file.js in the project-folder. It seems my CodeKit config is processing js-files (see screenshots 2-4).
Also, I see there is a lot of Foundation scripts and js I will not use, what is the best way within the current setup to exclude Foundation components and css files?
Thanks for you great help! I will send you a link to the site when I'm getting closer to launch :) Best regards, |
Hi @konsulenten, I think part of the confusion stems from using Gulp and CodeKit - they are very similar tools. You really only need to use one. Compiling JS Removing Unused JS/CSS from Foundation PS - It does look like some changes have been made in JointsWP compared to the version you are using. However, nothing major. |
Thanks a lot for the help @JeremyEnglert ! I've gotten quite into the structure of things now, so its great fun to work with this project. I think I will download the latest JointsWP and replace the .js-files of the theme. I see you have dropped the app.min.js among others... I have a few small questions about some other parts, just need some advice :) Will send email. Best regards, |
👍 |
I have a few custom JavaScript-files that is to be added in the project. Some built by myself and some libraries that could be called from Bower.
I've added Instafeed.js to Bower-components and want to add that to some of the pages and post types in the site. To make it work, I added it in a custom footer.php.
I will also use probably use some libraries on all pages (maybe Isotope or similar).
Some of these depend on JQuery and I noticed that they have to be loaded after JointsWP JQuery in order to work.
What are the best practices to solve this?
We probably want these files minified with the rest through Gulp etc?
Best regards,
Reidar Nygård
The text was updated successfully, but these errors were encountered: