0

I've created a CMS block with basic HTML, but I want to add my own custom Jquery.

I've been working on a timer project, I've done my own timer and the HTML and the styling are all prepared. But the only thing I need is a location for the custom Jquery.

I have no idea where this should go!

asked Feb 13, 2018 at 10:59
6
  • Hi! Welcome to Magento Stackexchange, do you want this Jquery to load on every page or just this specific page/block? Commented Feb 13, 2018 at 11:01
  • Also, I love the word nooblet and do you have a theme if you want this jquery to run on every page? Commented Feb 13, 2018 at 11:02
  • It will be located in the header so it's going to need to be every page. Commented Feb 13, 2018 at 11:03
  • We've got a purchased theme. (So I'm editing their theme. A LOT) Commented Feb 13, 2018 at 11:04
  • Alright, do you have a theme? Are you using require JS and/or have you already linked to a Jquery CDN? This is achievable by putting your jquery inside a javascript file and then telling Magento to load your file using default_head_blocks.xml Commented Feb 13, 2018 at 11:06

1 Answer 1

0

From my conversation in the comments with you You're going to need to go to paste your Jquery inside web/js and call it something like, lets say function.js. Save this inside that folder, next go to Vendor/Theme and if there's a Magento_Theme folder there go inside layout and click on default_head_blocks.xml. If not, you will need to create this file structure. (vendor/theme/magento_theme/layout/default_head_blocks.xml). Inside here you're going to want to insert <script src="js/function.js"/> line just after

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
 <head>

if you're making this file you then want to write

 </head>
</page>

after it. Save, flush cache and reload the page and the file should be referenced in your head. If it is but it isn't working, you can also use this to insert a Jquery cdn. I hope i've helped

answered Feb 13, 2018 at 11:12
1
  • Anytime! Welcome to the community! Commented Feb 13, 2018 at 11:44

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.