Inserting html codes in WordPress custom meta Fields

I have created custom meta fields in the functions.php file. The problem I am facing here is that when ever a html code such as <a href="example.com"></a> is inserted and saved, the meta box incorporates the code and the box now only displays <a href=". If the user were to then save the post again <a href= will be added to the page which can lead to numerous errors. Is there a way to format the metafield to contain the codes instead of merging it as part of the meta field markup it self.

My meta fields are currently like this

Read More
"example_name" => array(
"name" => "example_name",
"std" => "",
"title" => "Example",
"description" => "Example text")

Please your help will be much appreciated..also I’m looking for codes, not a plugin for my solution.

The HTMl is inserted like this

if($meta_box_value == "")
$meta_box_value = $meta_box['std'];
echo'<input type="hidden" name="'.$meta_box['name'].'_noncename" id="'.$meta_box['name'].'_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';
echo'<h2 style=" margin:0px; padding:0px 3px; font-style:normal; font-family:Tahoma; font-size:13px;font-weight:bold;">'.$meta_box['title'].'</h2>';
echo'<input type="text" name="'.$meta_box['name'].'_value" value="'.$meta_box_value.'" size="95" /><br />';
echo'<p><label for="'.$meta_box['name'].'_value">'.$meta_box['description'].'</label></p>';

Related posts

Leave a Reply

1 comment