Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

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

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

3 Answers

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
add comment

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
add comment

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();">
<option>1</option>
<option>2</option>
</select>

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
add comment

Your Answer

 
discard

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.