Hi,
I am programmatically creating posts and for the content of a post I would like to have some text and a link using the HTML <a>
tag.
However, as per
https://developer.wordpress.org/reference/functions/wp_insert_post/
wp_insert_post() passes data through sanitize_post(), which itself handles all necessary sanitization and validation (kses, etc.).
Eg if I set:
$post_content = $item_description.'<br><br><br>'.$item_url;
And then do:
// Create post object
$my_post = array(
‘post_title’ => wp_strip_all_tags( $item_title ),
‘post_content’ => $post_content,
‘post_status’ => ‘publish’,
‘post_author’ => 1
);// Insert the post into the database
wp_insert_post( $my_post );
Then the <br>
tags are stripped out in the actual post content.
I also tried <p>
which is stripped out as well and so I would think <a>
would be stripped out as well.
Is there a way to insert html especially <br>
and <a>
tags into post content?
Thanks ahead of time for any help.
EDIT – I found a bit later that when I added anchor tags, these tags were not stripped out.
Resolved.