Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Embedding Javascipt Into Wordpress Posts


5 replies to this topic

#1 Nelson Blogs

    Member [Level 3]

  • Kontributors
  • PipPipPipPipPipPip
  • 96 posts
  • Gender:Male
  • myCENT:28.52

Posted 21 February 2010 - 01:25 AM

I was wondering if there was any way to embed some javascript code into a WordPress post?  I try and put the code into my post but all that it does is display the code text.  I tried to look for a plugin but I had no luck finding one.

#2 BuffaloHelp

    Sterling Archer

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 4,088 posts
  • Gender:Male
  • myCENT:50.18

Posted 21 February 2010 - 06:23 AM

Are you trying to insert javascript on each post as it appears? Or, are you trying to insert javascript as a footer, header?

You can insert your javascript in item.php of your THEME, insert between anywhere you wish to attach.

You can insert your javascript header, head or footer files.

In your admin panel, you can add a custom box for any HTML codes (not tested with javascript from my end). Just go to Appearance > Widgets > and drag TEXT to the sidebar. Then, you can insert any HTML code which will be used on every sidebar.

#3 mahesh2k

    Trap Double Mocha Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 2,347 posts
  • Gender:Male
  • Location:Valley of Darkness
  • myCENT:67.95
  • Spam Patrol

Posted 21 February 2010 - 06:40 AM

I think this is what you need to read : http://codex.wordpre...sing_Javascript

I've seen that java-script files are stored separately in js folder. That allows it is easy to organize if you've lot of code to put into. In documentation there is way mentioned how to add into template files or link external.

I hope the documentation link that is given in this post will answer most of your questions. If not, let me know what exactly you're trying for. I'll see with what i can help.

#4 Baniboy

    Advocatus Diaboli

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 878 posts
  • Gender:Male
  • Location:/root
  • Interests:Everything...
  • myCENT:53.03

Posted 21 February 2010 - 10:08 AM

You weren't very clear about this, so I'm going to assume you want to add a small piece of javascript to every post on your blog. In case that was what you meant (this can be used for loading comments with ajax for example or some other interactive function).

This depends on the theme you have. Try to find the php file(s) in your theme that load the posts(some themes have separate archive, single etc. files for loading). Now, what you do is you search for the loop that's used to get your posts. There should be php functions such as wp_posts(), x_storytitle(). Insert your javascript where you want it to be in a post and you can also modify the post content's displaying order a bit.

This is for embedded javascript. A much easier way to do this is view source in browser and search for the IDs of post elements in the post, then apply external javascript to those by getElementbyId in the .js file(s).

#5 Nelson Blogs

    Member [Level 3]

  • Kontributors
  • PipPipPipPipPipPip
  • 96 posts
  • Gender:Male
  • myCENT:28.52

Posted 22 February 2010 - 10:44 PM

Sorry for not being clear in my topic above. I need javascript in a single post, not all of them. I cannot put it in the footer or the header because then it would become site-wide. Thank you so much for your help

#6 linekill

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 249 posts
  • Gender:Male
  • Location:Philippines
  • myCENT:45.61

Posted 20 March 2010 - 11:25 AM

I'm not that familiar with WordPress but I did use it before.. If you want to embed a JS on a single post, why not create a copy of theme..say you have a Page.ph, copy it and create a Page2.ph and use it as a template of that single page where you want the JS to appear...and put the Javascript on the Page2.ph file..

This is the only answer I can think of so far...Will post for new idea..




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users