Aurooba and Brian explore the new WP_HTML_Tag_Processor that landed in WordPress 6.2, and how handy it would be in scenarios where they've had to use regular expressions to modify HTML in their WordPress projects. They then walk through a function using the new processor to inline and safely modify SVGs, ways they could improve the function and take advantage of the processor's capabilities more, and discuss other ways the processor could enhance complicated filtering of rendered output in WordPress.
A full transcript of the episode is available on the website. Watch the video podcast on YouTube and subscribe to our channel and newsletter to hear about episodes (and more) first!
- The code from this episode – https://github.com/viewSourcePodcast/viewSource-blocks/tree/episode/html-tag-processor
- Aurooba's post with a walkthrough of the code – https://aurooba.com/inline-svgs-in-your-wordpress-code-with-this-helper-function/
- The Dev Note – https://github.com/WordPress/gutenberg/issues/44410#issuecomment-1420787816
- Brian's website – https://www.briancoords.com
- Aurooba's website – https://aurooba.com
- PHP Inline SVG helper function from Ian – https://gist.github.com/ian-svoboda-prom/b7a436d5397e007b7d8d5427465ff161
- Gist to get the file contents of an SVG – https://gist.github.com/rugor/1decc15655891825d15a7024a06d898b
- WP SVG Helper functions – https://gist.github.com/kingkool68/6d72977fe8c82eeb9a85295ac3623cde
- How to Modify HTML in a PHP WordPress Plugin Using The New Tag Processor API – https://adamadam.blog/2023/02/16/how-to-modify-html-in-a-php-wordpress-plugin-using-the-new-tag-processor-api/