Inserting html codes in Wordpress custom meta Fields

Go To StackoverFlow.com

1

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

"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>';
2012-04-04 17:22
by Craig
How is the html code inserted - Dion 2012-04-04 17:50
Thanks for the fast response, I just edited the question to show the html implementatio - Craig 2012-04-04 18:03
hm. maybe use htmlspecialchars() - Dion 2012-04-04 18:06
Yes! Thank you very much! You saved me a lot of trouble and time with such a simple solution - Craig 2012-04-04 18:34


2

Use the htmlspecialchars()-function in PHP.

2012-04-04 18:44
by Dion
Ads