Storing javascript in a Custom Field textarea

Code Snippet Related Categories

Reason for needing the Code Snippet

For some client projects I needed to embed javascript code in a page (Post). I used a custom field textarea to insert the code when creating the Post. The problem was the default for text fields was to run them through a sanitizer.php to strip out any type of code that might be malicious. This is a good thing. But in this case it defeats the purpose.

So how to disable the sanitizing for just this field without breaking the default?


(This post was viewed 453 times) in the last month.)

What the Code Snippet does

This is how to disable the sanitize.php functionality on a custom text field created with Custom Fields without editing the sanitize.php file in the metabox plugin, or for that matter writing any code at all.

Here's the Code Snippet

It turns out to be so simple, there's an Advanced tab on the settings for the custom textarea field where you can add an Attribute. The "sanitize_callback" with the value "none" is one such Attribute. So that's really all you have to do.

No longer do I need to edit the sanitizer.php file and comment out the textarea field on line 89 everytime the metabox plugin gets updated!

I used to have to comment out line #89 in the plugin sanitizer.php file every time the Metabox plugin got updated :-(

Below is a short video from Anh Tran the developer made showing how to set the textarea custom field attribute "sanitize_callback" to "none"

20 March, 2020 - Loom Recording — Watch Video

Limit search for phrases by using " " around the phrase

Subscribe to Code Snippet updates

You will get an email the morning after we post a new Code Snippet

Something went wrong. Please check your entries and try again.

Other Recent Code Snippets

Post Format: Aside

Posted in

“I never tried to prove nothing, just wanted to give a good show. My life has always been my music, it’s always come first, but the music ain’t worth nothing if you can’t lay it on the public. The main thing is to live for that audience, ’cause what you’re […]

Read More

Post Format: Status

Posted in

WordPress, how do I love thee? Let me count the ways (in 140 characters or less).

Read More

Post Format: Link

Posted in

The WordPress Theme Review Team Website

Read More

Post Format: Quote

Posted in

Only one thing is impossible for God: To find any sense in any copyright law on the planet. Mark Twain

Read More

Post Format: Chat

Posted in

Abbott: Strange as it may seem, they give ball players nowadays very peculiar names. Costello: Funny names? Abbott: Nicknames, nicknames. Now, on the St. Louis team we have Who’s on first, What’s on second, I Don’t Know is on third– Costello: That’s what I want to find out. I want […]

Read More

Pieter Hartsook

WordPress website coaching, design, implementation, support, and training. Background in Marketing Research and Communications. See my profile at:

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *

Skip to content