Vinu Sebastian
Vinu Sebastian

Reputation: 568

How to add a script in wordpress theme footer dynamically

I wish to create a wordpress plugin to add below script in all pages. So I need to add that script in theme footer. How can I add it in footer.php using plugin?

eg script =

script type="text/javascript" src="sample.js">

also I wish to add it in before body closing tag..

Thank you..

Upvotes: 3

Views: 1068

Answers (2)

pythonian29033
pythonian29033

Reputation: 5207

for a javascript script you can just open the footer.php file and add the reference in there before the closing body tag, or use an include if it's a php script;

...
   <script type="text/JavaScript" src="yourscript.js" />
   <?php
      include("yourscript.php");
   ?>
</body>
...

PS: make sure that your .js file is in the same directory as your footer.php

Upvotes: 0

user2672373
user2672373

Reputation:

Use wp_enqueue_script to load the script in your themes functions.php file. Else, directly embed the script in your themes footer.php file.

Upvotes: 2

Related Questions