For one of my current projects, I had to transfer blogposts from an old WordPress site to my project.
Things went smoothly until I’ve seen that all the posts were copy pasted from Word, leaving this before pretty much every paragraph:
<span style="font-size: medium; font-family: georgia,palatino;">
And at some places things like these:
<p style="text-align: justify;">
<p style="text-align: justify;"><span style="font-size: medium; font-family: georgia,palatino;"><strong><span style="color: #000000;">
So because I don’t have the 40 hours (even less the patience) to just go into every post (there’s about 100) and remove those unwanted tags, I’m looking for a filter that would just remove all style (except maybe if it contains text-decoration:underline) elements before outputting the_content()
Is there such a thing?
If we want to remove all inline styles, then just simply need to add the following code in functions.php.
Just add this to your functions.php.
I tried the method above with the saving/updating but didn’t worked for me so I went from another approach. I exported the whole wp_posts table, opened it in Sublime and did a regex replace. I used
style="*.*?"
to find all cases and replaced them with emptyness. Then droped the old table’s content and imported the new one.If any one try this method – please make sure you have a clear back up in case there are some other post types in the wp_post table and the things got bit messy.
I would check out the content_save_pre filter, and probably apply some fancy regex at that point.