I have added a meta field for text input. I want to allow some html tags such as <strong>
and <i>
For example: <strong>hello</strong> world
I can save the input field value without sanitizing and its no problem this way:
if( isset( $_POST['my_field'] ) ){
update_post_meta($post->ID, 'my_field', $_POST['my_field']);
}
However if I use the sanitize_text_field
function as following, it will remove the html tags when saving:
if( isset( $_POST['my_field'] ) ){
update_post_meta($post->ID, 'my_field', sanitize_text_field($_POST['my_field']));
}
What would be the best way to sanitize values with html tags in it before storing?