Jump to content


This topic is now archived and is closed to further replies.


How to add a script (loaded from child-theme folder) and inline javascript to the footer properly?

Recommended Posts



What is the best way to achieve this? 

If I wan to add a  anything.js script file to the footer, and add some inline javascript (to for example load the js plugin I just inserted), how should I do this?

Should I just add them to the footer.php?

What if I want a custom-made section to insert them in the footer?  Most of the time they need to be loaded after jQuery, and often it's also best if they're after the site content. 


I can load a script with:

function section_styles(){
// This will load the 'cooljavascript.js' file from the current section folderwp_enqueue_script( 'my-js-plugin', $this->base_url.'/cooljavascript.js', array( 'jquery' ), PL_CORE_VERSION, true );}

But how to initalize the plugin I just loaded?


I also want them to be in my project under git and/or in the specific section that needs the script and initialize it, I don't want them i.e with Hooker so it's in the database. 

So can I use some hook in my functions.php? 
Also, can I use hooks to insert js or other things to the site in custom made functions?


Share this post

Link to post
Share on other sites

What if my scripts are linked with a section?

For example I'd like to load masonry.js with a section that gets posts and uses masonry on them? 
Can I use hooks in sections?





You can use hooks in your functions.php file, that is the primary reason for a functions.php file. You should use the Wordpress enqueue.



Share this post

Link to post
Share on other sites
James B

Hi there,


If you activate the actionmap plugin which comes within the Pro Tools plugin this will show you all the hooks on the page, inside of each main area/section etc. Usually each section will have 4 hooks inside it. The action map plugin will show you where these hooks are positioned on each page, then you can use the one closest to the area you require to position your script to activate.

Kindly search the forum and read the documentation before posting. It will help you resolve many issues.

For CSS help be sure to check out W3Schools first and be sure to download FireBug for FireFox for troubleshooting.

James B

Share this post

Link to post
Share on other sites

  • Similar Content

    • Paul
      By Paul+
      I was surprised to see I had no menu today - out of the blue - its actually moved to the bottom of the page!  After hours of fiddling and disabling every single plugin, leaving just plagelines the issue is still present.  See video for a basic text box - I moved it into the head and it jumps to the bottom and shows just above the footer but below the main content.  I have a temp fix by placing the menu into the first row on the main content but it does mean other than my home page, all other pages have no menu.  A quick fix is very urgent for this bug.
    • Michael Kummer
      By Michael Kummer+
      Hi guys!
      I am using a plugin called Speed Booster Pack to speed up the load time of michaelkummer.com. One of the plugin settings, Minimize HTML and JavaScript causes an error that I only get with Pagelines. With other themes, such as WordPress' Twenty Seventeen, I do not get that error.
      I have reproduced the problem on my staging site and if you look at the JavaScript console, you will see the following error:
      SyntaxError: Unexpected end of script
      Any clue what PageLines may be doing differently to be contributing to this issue? I contacted the plugin developer and they, of course, pointed me to the theme developer
    • flourishdesignstudio
      By flourishdesignstudio+
      We are working on a site and the customers are complaining that the site loads too slowly. They contacted their host who mentioned that the Java Script is all loading at the beginning. Is it possible to delay the load of the less important Java Script until after the initial load to speed up the site? The goal is to load the page faster by minimizing the initial javascript calls.
      Are there any preferred plugins that you would recommend or does this end up causing excessive problems with plugins, etc.?
      Thanks for the help!
    • cas45
      By cas45+
      I am running a site based on PageLines Framework 2.5.0. I am making some changes to a current website and managed to find a script that will do what I want.:
      $(".vend-cat").each( function() {
          if ( $(this).find(".no-vendors").html() == '' ) {
      } );
      I have tested it on jsfiddle and it works fine. It does however need to be adapted to work with jQuery for pagelines and wordpress. Any help or advice?
    • unifeyed
      By unifeyed+
      Hello there. 
      I am trying to have all the ® symbols throughout my website superscript without having to individually go to each symbol and wrap them in <sup> tags. There is quite a bit of them. I have the following code within the Custom Scripts, but it seems to cause issues with the Hamburger navigation, as it does not seem to work. Can you offer up some assistance? 

      jQuery(document).ready(function() {
          jQuery("body").html().replace(/®/gi, '<sup>®</sup>').replace(/®/gi, '<sup>®</sup>')