Strip Posts of font styling (4 posts)

  1. masok88
    Posted 3 years ago #

    Hey everyone,

    I recently took on a site which I've converted to Joomla to WordPress. One of the issues I've noticed however is my client has a series of posts by a number of different authors who it looks like wrote their documents in Microsoft Word and they've copied and pasted the entries into their CMS.

    Is their a way to strip existing posts in the wordpress database of their font styling (color, typeface size) etc. and default to the css attributes? I've tried a few different ways but they all strip out the actual paragraphs themselves too. Is there a way to just target the styling of the fonts themselves, at the moment I have about 100 posts with nearly all of them in an inconsistent format and don't really want to ask my client to go through and amend this unless I really have to.

  2. s_ha_dum
    Posted 3 years ago #

    Is there a way to just target the styling of the fonts themselves...

    I don't think so. Those are probably inside 'style="..."' attributes, which take precedence over anything you can do in a stylesheet, or in a 'style' tag.

    You should be able to delete that 'style' attribute using preg_replace and a carefully constructed regex rule.

  3. masok88
    Posted 3 years ago #

    thanks for getting back to me got any ideas on how I would do that? Did a google and didn't come back with anything.

  4. s_ha_dum
    Posted 3 years ago #

    I offered a suggestion-- preg_replace. Something like:

    $str = preg_replace('/style=[\'"][^\'"]*"/','',$str);

    caveat emptor: That works on my test case, unless I have a typo in the transcription. It is not by any stretch adequately tested. Don't trust it with important data until you have done some significant dry runs with dummy data. If you know for certain that your style is wrapped ing double quotes you can use " instead of [\'"] and [^\'"]

Topic Closed

This topic has been closed to new replies.

About this Topic