Recently I was using the wp_insert_post function of wordpress to make a post through a plugin. The problem is that this function removed the styling element I included. For example I used this:
and after posting this through wp_insert_post it got like this:
I search for a solution for a couple of days but I couldn’t find a straight answer. Anyway, as it turned out it’s not such a hard problem. I am not a wordpress wizard (not even close ) but I believe I solved my problem.
Locate the file /wp-includes/kses.php . This function is called when you make a post to filter out all the bad things that may be a risk for your blog. At line 44 (on my file) you can see an array of allowedPostTags. If you take a look you can see that what I was trying to add i.e. the id it is not conained in the div sub-array. That is the reason why it was removed. So I believe you can do 2 things:
- You can use an allowed tag instead. This is what I did. I noticed that div class was an allowed tag so I used that instead of div id. Not much difference for me and it worked.
- I believe you can also manually add the id tag in the div sub-array in the same way as the other tags are added and it wont be removed. I have’t tested that but I am pretty sure it would work
Anyway, that’s all. I hope you can solve your problem. Let me know in the comments if you need some help.
Incoming search terms:
- wp_insert_post (16)