I'm using a custom field to display images in a slider on each post, but when I update the post after having entered the HTML code in the custom field, the code disappears. I'm assuming that there is some kind of filter that removes HTML code from custom fields when a post is saved. Is there a way to circumvent that without using a plugin?


Edit: The information is saved using the following code:

function save_details(){
    global $post;

    update_post_meta($post->ID, "ptime", $_POST["ptime"]);
    update_post_meta($post->ID, "services", $_POST["services"]);
    update_post_meta($post->ID, "tools", $_POST["tools"]);
    update_post_meta($post->ID, "url", $_POST["url"]);
    update_post_meta($post->ID, "images", $_POST["images"]);

You can find the complete functions.php code here (Pastebin).

  • 1
    No, there is no such filter by default. How is the field saved? Add this information to your question to make answers possible.
    – fuxia
    Commented Jul 7, 2012 at 13:25
  • 1
    Updated the main post. Commented Jul 7, 2012 at 13:31

1 Answer 1



The correct function to use in context to WordPress and its intended API for this purpose is;


Thus your code would reflect something like this;

<textarea><?php echo esc_textarea($images);?></textarea>

Although htmlspecialchars and htmlentities are valid to use, and even though esc_textarea wraps htmlspecialchars anyway, its more appropriate to use the official API call.

I've left my original answer below for reference purposes, however swap out the relevant functions as needed.


In your snipped at Pastebin replace your images_box function with (start of line 65);

function images_box($echo = FALSE){
  global $post;
  $custom = get_post_custom($post->ID);
  $images = $custom["images"][0];
  <textarea name="images" cols="100" rows="10">

      <?php echo htmlspecialchars($images); //Hi, I'm your input! ?> 


You were not echoing the value of your input between the <textarea> ECHO INPUT HERE </textarea> tags thus it appears you were not entering anything at all.

Also wrap your input with htmlspecialchars

Also $city = $custom["images"][0]; should be $images = $custom["images"][0]; (line 68)

  • I am using WPEngine that doesn't allow me to modify files in wp-includes directory. Is there any way to make it work using theme functions.php?
    – Syed Priom
    Commented Jun 8, 2015 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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