Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress add javascript in footer

I need to add a script in the site footer. I'm just referencing the footer.php:

<script src="wp-content/file/script.js"></ script>

At Home functions normally, but when access a page child he does not find because search the directory:

site/page-child/wp-content/file/script.js.

I saw that I have to use:

  wp_enqueue_script ()

But where should I put this code?

Thank's

like image 493
Daniel Avatar asked Mar 19 '26 11:03

Daniel


1 Answers

You just need to add a "/" before your url in order to start it from root like :

<script src="/wp-content/file/script.js"></ script>

Indeed at home page it looks for yoursite.com/wp-content but on other pages it searches yoursite.com/current-page/wp-content and obviously it results in 404.

Adding / make it always look for yoursite.com/wp-content

like image 160
Villeneuve Michaël Avatar answered Mar 22 '26 00:03

Villeneuve Michaël