• OsakaWebbie

    (@osakawebbie)


    I and others have been updating the website of a magazine to the Gutenberg era, converting a bunch of old “Classic block” content to blocks. After this had been done quickly for many posts, I’ve now discovered that there is inline stuff that is getting in the way of things working properly, especially in headings. Is there a way to strip classes and span tags without editing the HTML manually for every block?

    For example, here is what a typical heading looks like:
    <h4 class="p3"><span class="s1">The path to Japan</span></h4>
    The class on the heading tag is harmless, but the <span> is preventing the heading from being the color specified for headings in my CSS. I can see in the visual editor that there is some sort of inline tag (span, em, strong, etc.) by the gray background when I put my cursor in it, but I can’t remove the span without selecting Edit as HTML, manually removing the pair of tags, and then selecting Edit Visually. Every heading is like this, so that’s a lot of work!

    In fact, ALL the blocks (including paragraphs) have a class on them – “p1”, “p2”, etc. I don’t know where that stuff came from, but it has nothing to do with our current theme and CSS. As I said, it’s harmless, but I’d love to see it disappear.

Viewing 2 replies - 1 through 2 (of 2 total)
  • barnez

    (@pidengmor)

    If there are only a limited number of style tag types, one option might be to do a find and replace in the database e.g.

    <h4 class="p3"><span class="s1"> >>> <h4>

    </span></h4> >>> </h4>

    Backup first of course, and test carefully afterwards.

    EDIT:

    You could target the wp_posts table specifically to avoid affecting any of the theme settings.

    • This reply was modified 3 years ago by barnez. Reason: Add suggestion about targetting the wp_posts table
    Thread Starter OsakaWebbie

    (@osakawebbie)

    Yeah, that might work. But the second replacement (to remove </span>) in isolation would be risky, so doing them in one statement instead of two would be a lot safer. I wish I was a whiz at regular expressions – anyone want to help with how to use MySQL’s flavor of regex to do this?

    It seems that a “Clear all inline styling” command in Gutenberg would be helpful for more than just this situation. (Perhaps it would be most broadly useful at the block level, like on the same menu where Edit as HTML is, or on the Block tab in the right pane.) I’m really surprised it doesn’t already exist.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to strip old classes and spans’ is closed to new replies.