WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In WordPress when i publish a page with JS code is ignored and don't returns anything.

How can I make sure that when I write a HTML+JS code will be converted to output?!
Like: <a class="print" href="#" onClick="window.print();">PRINT</a>

Thank you! and sorry for my weak english!

share|improve this question

migrated from stackoverflow.com Nov 11 '11 at 19:27

This question came from our site for professional and enthusiast programmers.

onclick is not i the list of allowed attributes. It will be removed by kses. You can filter the list, use Extend KSES for example.

share|improve this answer

I just tried this in a post of the latest WP install:

<script>function update(){alert('this is the update box');}</script>

<select name="cities" id="cities" onchange="javascript:update();">

This seemed to work fine.

You will probably encounter that if you have any lengthily code for javascript that maybe then you should put that code into a file and point to it in the post/page. Like so:

<script src="path_to_javascript_file"></script>

But one other note. I generally do not want this .... If a site or a page needs to have some javascript added then maybe you need to ask yourself why.

IMHO for javascript and anything that can be lengthily in nature I would prefer to write a plugin.

share|improve this answer

I think you are entering this code in WYSIWYG Editor and not in HTML.

Everything you enter in HTML view is rendered and everything you enter in WYSIWYG Mode is displayed as you type.

For example <a href="http://wordpress.org">WordPress</a>

will become WordPress

share|improve this answer
now works, but with input tag like: <select name="cities" id="cities"onchange ="update()"> doesn't gives me the result. – humanbeing Nov 11 '11 at 21:47
I changed the question to Why the JavaScript code is ignored from wp editor? – humanbeing Nov 11 '11 at 22:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.