Improving RSS Feeds: Resolving Warnings in RSS Validator and Removing Attributes with MySQL
In a previous article, we used the W3C Feed Validator to validate the WordPress RSS feed. At that time, we confirmed its well-formedness as XML and cleared the basic checks. However, in reality, issues remained where some RSS readers and apps failed to display posts correctly due to extraneous attributes. Therefore, this time we used the official RSS Advisory Board Validator to check the feed more strictly.
Checking with the RSS Validator
Upon verification with the Validator, we found that numerous attributes originating from Gutenberg and plugins still remained, such as:
- data-start, data-end
- data-spread
- data-col-size
- data-pm-slice
While these attributes do not affect browser rendering, they are unnecessary in RSS feeds and can become a factor in reducing compatibility.
Batch Removal Using MySQL
Post contents are stored in the post_content column of the wp_posts table. Therefore, we accessed MySQL directly to remove the unnecessary attributes.
-- Remove data-start UPDATE wp_posts SET post_content = REGEXP_REPLACE( post_content, '[[:space:]]data-start="[^"]*"', '' ) WHERE post_content REGEXP 'data-start='; -- Remove data-end UPDATE wp_posts SET post_content = REGEXP_REPLACE( post_content, '[[:space:]]data-end="[^"]*"', '' ) WHERE post_content REGEXP 'data-end='; -- Remove data-spread UPDATE wp_posts SET post_content = REGEXP_REPLACE( post_content, '[[:space:]]data-spread="[^"]*"', '' ) WHERE post_content REGEXP 'data-spread='; -- Remove data-col-size UPDATE wp_posts SET post_content = REGEXP_REPLACE( post_content, '[[:space:]]data-col-size="[^"]*"', '' ) WHERE post_content REGEXP 'data-col-size='; -- Remove data-pm-slice UPDATE wp_posts SET post_content = REGEXP_REPLACE( post_content, '[[:space:]]data-pm-slice="[^"]*"', '' ) WHERE post_content REGEXP 'data-pm-slice='; -- Remove data-is-only-node UPDATE wp_posts SET post_content = REGEXP_REPLACE( post_content, '[[:space:]]data-is-only-node="[^"]*"', '' ) WHERE post_content REGEXP 'data-is-only-node='; -- Remove data-is-last-node UPDATE wp_posts SET post_content = REGEXP_REPLACE( post_content, '[[:space:]]data-is-last-node="[^"]*"', '' ) WHERE post_content REGEXP 'data-is-last-node='; -- Remove data-blogcard UPDATE wp_posts SET post_content = REGEXP_REPLACE( post_content, '[[:space:]]data-blogcard="[^"]*"', '' ) WHERE post_content REGEXP 'data-blogcard='; -- Remove data-attributes UPDATE wp_posts SET post_content = REGEXP_REPLACE( post_content, '[[:space:]]data-attributes="[^"]*"', '' ) WHERE post_content REGEXP 'data-attributes=';
Here, we used [[:space:]] to ensure reliable removal even if line breaks or tabs are present in addition to spaces. Since MySQL 5.x does not support REGEXP_REPLACE, you would need to repeat REPLACE for each individual attribute.
Verification
After executing the SQL and checking again with the RSS Validator, the warnings related to these attributes disappeared. We also confirmed that articles are now displayed properly in feed readers.
Future Tasks
Warnings still remain for attributes originating from image tags, such as fetchpriority, decoding, and sizes. Because WordPress adds these automatically, it is safest to add a filter in functions.php to remove them only when outputting the feed. In the next post, I plan to summarize how to strip these attributes and further reduce Validator warnings.