Support » Fixing WordPress » JavaScript into single post

  • Hello, newbie question here. I need to add a form that requires Javascript to a single post on I’m trying to understand this section about adding JS:

    JavaScript in Posts

    For the occasional or one time use of JavaScript, you need to put the script into a JavaScript file and then call it out from within the post. Make sure that each script is defined by its function name such as:

    Where does this JS file go, once it’s created?

    Thanks in advance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • If after spending the time to review the Codex on such issues and you have not been able to proceed well, our continued advice is to either continue to study and apply at a not live site or dev site and not your main site, and if unable to do so please consider hiring an expert. We cannot rewrite the Codex today. Tomorrow maybe 🙂

    That said, the code to your .js file goes in header.php or footer.php (theme requirements ensue) and requires knowledge of at least HTML and likely PHP.

    Where do you read a request to rewrite anything? I’m asking for the procedure to be explained in a more granular manner. And I would have preferred to ask the question in a thread already going on re the same topic, but was told by a mod to start a new question.

    If you want to add JavaScript to a post, you can just add it to the post itself by enclosing it in <script> … </script> tags. I do it all the time usually right at the beginning of the post. Just make sure you’re editing the post using the Text editor and not the Visual editor.

    Thanks CB. Wasn’t that easy for me. But I figured it out. Now visitors can use a price comparison to value tool on my site:

    Here’s some advice that hopefully will prove useful to the next person who searches on this issue:

    1. Always use Text Editor. This means using the Text editor the last time you edited anything – otherwise the post automatically opens in Visual.

    2. Get a plugin that ensures that WP doesn’t edit your pasted code in any way. I used Raw HTML.

    That SHOULD work, without getting into any header or footer file issues, no saving a js file and calling to it, etc.

    THANK YOU cparente! I was looking at all the other javascript info pages and it was way too complicated for what I wanted to do (embed a form on a page). Using raw HTML worked perfectly.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘JavaScript into single post’ is closed to new replies.