0

I need to include specific Javascript files on specific posts. This will be done in pretty much every post and each file is unlikely to be included in more than one post. I know I could just upload the files via FTP and put a <script> tag at the bottom of the post, but I would like to do it all from the dashboard.

So I want to create a custom field in post-new.php where I can upload javascript files to the database, then in single.php I add a line of code that includes the files at the bottom of the page.

What's the best way to achieve this?

0

1 Answer 1

1

Upload the file as media/attachment, add post meta data and add it as dependency to the footer via the Dependency API.

2
  • Quick question, is there a reason why I should use the Dependency API instead of a simple <script> tag? Commented Nov 17, 2014 at 18:04
  • Because you can handle stuff easier, plugins that concatenate and compress scripts can take it into account, you get it at the right position in the DOM, etc. Commented Nov 17, 2014 at 18:16

Your Answer

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.