Is there a way to use JQuery inside a WordPress post?

5 replies
Is there a way to use JQuery inside a WordPress post?

I want to use JQuery effects inside the content area of a post (not just in the header, sidebar, or footer).

I think there's a RAW HTML plug-in of some sort for WordPress, but I'm not sure it allows PHP or JQuery/Javascript to be executed.

Thanks,

John
#inside #jquery #post #wordpress
  • Profile picture of the author LakiPolitis
    Once your page has called the javascript library for jquery, you can write jquery wherever you want.

    Say this your post:

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac orci dapibus metus varius fringilla. Aliquam vitae tellus quis nulla pretium pellentesque in id nunc. Suspendisse turpis magna, consectetur in sollicitudin quis, suscipit non dolor. Ut adipiscing diam in leo ullamcorper dictum. Vestibulum non sodales odio. Morbi varius urna ut massa feugiat a pretium sapien rhoncus. In hac habitasse platea dictumst. Cras tincidunt auctor tristique. Donec et lorem est. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nulla cursus sagittis euismod. Pellentesque porta auctor convallis. Vestibulum a orci id mi mollis accumsan. Maecenas consequat ullamcorper lectus non placerat. Vivamus a enim at magna egestas sagittis. Nullam purus lacus, rutrum nec blandit vel, dignissim eget felis.

    you could literally do this:

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac orci dapibus metus varius fringilla. Aliquam vitae tellus quis nulla pretium pellentesque in id nunc. Suspendisse turpis magna, consectetur in sollicitudin quis, suscipit non dolor. Ut adipiscing diam in leo ullamcorper dictum. Vestibulum non sodales odio. Morbi varius urna ut massa feugiat a pretium sapien rhoncus. In hac habitasse platea dictumst. Cras tincidunt auctor tristique. Donec et lorem est.

    HTML Code:
    <script type="text/javascript">
    $(document).ready(function() {
      // Handler for .ready() called.
    });
    </script>
    Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nulla cursus sagittis euismod. Pellentesque porta auctor convallis. Vestibulum a orci id mi mollis accumsan. Maecenas consequat ullamcorper lectus non placerat. Vivamus a enim at magna egestas sagittis. Nullam purus lacus, rutrum nec blandit vel, dignissim eget felis.

    Hope that helps.
    {{ DiscussionBoard.errors[4800954].message }}
  • Profile picture of the author Johnny12345
    Hi Laki,

    Thank you for the info.

    Somehow I was under the impression that JQuery would not run *within* a post.

    -John
    {{ DiscussionBoard.errors[4801504].message }}
  • Profile picture of the author LakiPolitis
    It's not a good practice and it is highly frowned upon, but if you absolutely need to make that happen and have absolutely no other means to do it, you can do that. Again, I would suggest against it, but if you're stuck and you can't edit the template file, then use that strategy.

    If you don't mind me asking. What is it for? I may be able to suggest a better solution.
    {{ DiscussionBoard.errors[4801644].message }}
    • Profile picture of the author Johnny12345
      I want to be able to incorporate various types of simple interactivity within an individual post, so I don't think editing the template would help.

      I'm not sure why using JQuery within a post would be frowned upon. Either it will work or or it won't. If it works, I don't see the downside.

      Thanks,

      John


      Originally Posted by LakiPolitis View Post

      It's not a good practice and it is highly frowned upon, but if you absolutely need to make that happen and have absolutely no other means to do it, you can do that. Again, I would suggest against it, but if you're stuck and you can't edit the template file, then use that strategy.

      If you don't mind me asking. What is it for? I may be able to suggest a better solution.
      {{ DiscussionBoard.errors[4809061].message }}
  • Profile picture of the author LakiPolitis
    Then that's definitely your best bet. It's frowned upon, because you shouldn't put JavaScript into the body of a document. It should be in the header or footer of your HTML document. Preferably an external sheet.

    There's a lot of things that work out there, and most of them aren't intended for that purposes.
    {{ DiscussionBoard.errors[4809080].message }}

Trending Topics