0
Welcome Guest! Login
0 items Join Now

Adding javascript files to Gantry index.php header

  • Adding javascript files to Gantry index.php header

    Posted 10 years 3 months ago
    • What is the method for including javascript files in the Gantry header, which won't be overwritten with a gantry/template update?

      For a normal wordpress template, I would create a child theme and override index.php. But I can't see how to create a child theme of gantry because of the dynamic way css files are created by the LESS compiler. If there is a way then please let me know!
    • Freshpage Web Design
  • Re: Adding javascript files to Gantry index.php header

    Posted 10 years 3 months ago
    • Hi,

      You can add your custom javascipt files under theme's js folder and then call the addScript method of the global $gantry object:
          
      global $gantry;
      $gantry->addScript( 'customscript.js' );

      You can add the code above in index.php of the theme or in a widget in the page you want to use your js.

      Hope this helps :D
    • Posting a url to your site and screenshots of your issue could be really helpful.
      How to add a Custom Stylesheet in Gantry for WP
  • Re: Adding javascript files to Gantry index.php header

    Posted 10 years 3 months ago
    • Adding to index.php would be overwritten when the gantry theme is updated wouldn't it?

      Maybe I could put it in a widget but that seems a bit of a hack.
    • Freshpage Web Design
  • Re: Adding javascript files to Gantry index.php header

    Posted 10 years 3 months ago
    • Hi,

      Theme's index.php isn't affected by Gantry updates but only with theme updates and is one of the least changed files.

      Another way would be to use a plugin that will load automatically your js. Here is one, but i haven't tested so i can't predict the results.

      Hope this helps :D
    • Posting a url to your site and screenshots of your issue could be really helpful.
      How to add a Custom Stylesheet in Gantry for WP
  • Re: Adding javascript files to Gantry index.php header

    Posted 6 years 3 months ago
    • Almost four years on from this activity, is there any better way to include a js file short of creating a new particle in G5?

      Paula
    • Do'er of stuff
    • Wicko's Avatar
    • Wicko
    • Elite Rocketeer
    • Posts: 884
    • Thanks: 8
    • Self employed Graphic designer with over 20 years of experience in branding, retail packaging and web design.

    Re: Adding javascript files to Gantry index.php header

    Posted 3 years 7 months ago
    • Added custom js to Gantry 5 is easy. Simply go to you template and page settings tab. At the bottom of the page is the atoms section. Drag the custom CSS / JS to the panel below if not already added. Click the gear icon and add your customer CSS or JS there.
    • The following users have thanked you: Alexander Pape

    • This image is hidden for guests.
      Please log in or register to see it.

      Wicko Design is a multi-disciplined creative agency based in the South East of England. Specialising in web design & development, retail packaging and brand identity.

      https://www.wickodesign.com
  • Re: Adding javascript files to Gantry index.php header

    Posted 7 months 6 days ago
    • Yes, it is very easy to add code. But how can I add code to a particular place? I need my script (cookie banner) to be loaded before any other script. How?
      With almost every other template that's trivial. With Gantry, I can't figure it out :-(
    • Last Edit: 7 months 6 days ago by Ralf Longwitz.

Time to create page: 0.060 seconds