如何解决WordPress中的‘HTML标签col存在禁用属性’问题?
Fixing the "HTML tag col has disallowed attribute" Issue in WordPress
Hey there, I’ve dealt with this exact AMP-related headache before—let’s break down how to fix it step by step, since you’ve already checked the AMP plugin itself.
First: Track Down Where the Offending <col> Tag Is Coming From
AMP enforces strict rules on allowed HTML attributes, and <col> tags often get flagged if they use legacy attributes like width, align, or custom data attributes. Here’s how to find the source:
- Check your content tables: If you’ve manually inserted tables in posts/pages, or used page builders like Elementor/WPBakery to create them, switch to the editor’s "Text" (HTML) view to hunt for
<col>tags. - Inspect your theme templates: Some themes include table templates (for product tables, pricing layouts, or archives) that might generate
<col>tags with disallowed attributes. Dig into your theme’stemplate-partsorincludesfolders for table-related files. - Review third-party plugins: Table-specific tools (like TablePress) or content optimization plugins might auto-generate tables with problematic
<col>attributes. Temporarily disable them one by one to narrow down the culprit, then check their settings for AMP compatibility.
Next: Fix the Disallowed Attributes
Once you’ve found the source, here’s how to resolve the issue:
- Replace legacy attributes with CSS: Instead of using inline attributes like
<col width="300">, move that styling to your theme’s custom CSS or AMP-specific stylesheet. For example:/* Target the first column in your specific table */ .pricing-table col:nth-child(1) { width: 300px; } - Update plugins/themes: If the
<col>tag comes from a plugin or theme, make sure you’re running the latest version—developers often patch AMP compatibility bugs in updates. - Filter the output with a custom function: If you can’t edit the source code directly, add a PHP snippet to your theme’s
functions.phpfile (or use a code snippets plugin) to strip disallowed attributes from<col>tags:add_filter('the_content', 'fix_col_attributes'); function fix_col_attributes($content) { // Remove width, align, and custom data attributes from <col> tags return preg_replace('/<col[^>]*?(width|align|data-[^>]+)[^>]*?>/', '<col>', $content); }
Use Debug Tools to Pinpoint Exact Errors
AMP’s built-in validation tools will tell you exactly which attribute is causing the problem and where:
- Browser DevTools: Open your AMP page, right-click > "Inspect", then go to the "Console" tab. Look for AMP validation errors—they’ll highlight the specific
<col>tag and the disallowed attribute. - AMP Plugin’s Validation Log: In your WordPress dashboard, go to AMP > Validation to see a detailed list of errors, including the exact post/page where the issue occurs.
内容的提问来源于stack exchange,提问作者Sabeer Shaikh
相关产品推荐
相关产品推荐

