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

I try to save inline javascript(Google analytics code) in wp-options table. But i can't figure out what validation function i shall use.

I have tried esc_js when saving to the database. But i can't figure out what to use when i shall echo it in the head section.

share|improve this question
addslashes() and stripslashes() not work for you? – mor7ifer Mar 18 '12 at 18:44
Thank you very much, that solved it. – andeersg Mar 18 '12 at 18:56
I submitted it as an answer so you can mark as solved! – mor7ifer Mar 18 '12 at 18:59
up vote 0 down vote accepted

You can use addslashes() and stripslashes() to prepare any data for database entry. These are native PHP functions, not wordpress functions, so they do not necessarily need to be hooked anywhere specific in the wordpress load to work.

share|improve this answer
I just discovered that the output when using stripslashes is like this: <script type=\\\\\\\"text/javascript\\\\\\\"> I tought stripslashes removed them? – andeersg Mar 20 '12 at 9:58
One instance of addslashes() will be undone by one instance of stripslashes(). If addslashes() is being called more than once (I don't know why you would ever do that), then you will need to call stripslashes() the same number of times. It looks like you're calling addslashes() 3 times based on the number of slashes there are. – mor7ifer Mar 20 '12 at 10:33
Hm, i only use the function one time. Think i must really go over my code. Thank you very much :) – andeersg Mar 20 '12 at 11:09
How are you inserting the values into the database? – mor7ifer Mar 20 '12 at 11:15

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.