Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Best way to include custom javascript into Vanilla 2
patric
New
I'm trying to include a custom .js file into Vanilla 2 but i don't want to modify any of the core files like class.vanillacontroller.php. Has anyone done this successfully?
Tagged:
0
Comments
- Add your custom.js to /themes/Patric/js/custom.js
- Create a file called /themes/Patric/class.patricthemehooks.php
- Add the following to the php file:
Themes are always searched for js and css files first so your custom.js will always be given the highest priority.This will be very useful :-)
@Todd - I'm trying to get my theme's core.js as well as jquery.fitvids.js to run before some of the other JS files included with Vanilla. When I put this in my themehooks file, it runs, but it doesn't run before the other JS files. Example:
<script src="/js/library/jquery.js?v=2.0.18.8" type="text/javascript"></script> <script src="/js/library/jquery.livequery.js?v=2.0.18.8" type="text/javascript"></script> <script src="/js/library/jquery.form.js?v=2.0.18.8" type="text/javascript"></script> <script src="/js/library/jquery.popup.js?v=2.0.18.8" type="text/javascript"></script> <script src="/js/library/jquery.gardenhandleajaxform.js?v=2.0.18.8" type="text/javascript"></script> <script src="/js/global.js?v=2.0.18.8" type="text/javascript"></script> <script src="/applications/vanilla/js/bookmark.js?v=2.0.18.8" type="text/javascript"></script> <script src="/applications/vanilla/js/discussions.js?v=2.0.18.8" type="text/javascript"></script> <script src="/applications/vanilla/js/options.js?v=2.0.18.8" type="text/javascript"></script> <script src="/js/library/jquery.gardenmorepager.js?v=2.0.18.8" type="text/javascript"></script> <script src="/plugins/Voting/voting.js?v=1.1.1b" type="text/javascript"></script> <script src="/themes/Gunway/js/core.js?v=1.0" type="text/javascript"></script> <script src="/js/jquery.fitvids.js?v=2.0.18.8" type="text/javascript"></script>
This is being analyzed here via a Fitvids.js challenge - vanillaforums.org/discussion/23831/fitvids-js-breaks-layout-but-only-in-the-mobile-template#latest