You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AMP文章中重复canonical链接与标题标签的移除方法求助

Hey there, let’s work through this duplicate canonical and title tag issue in your AMP posts—this is a super common conflict between SEO plugins and AMP tools, so I’ve got a few targeted fixes to try:

1. First, Pinpoint Exactly What’s Adding the Duplicates

Before jumping into fixes, you need to know which component is doubling up on tags. Here’s how:

  • Open one of your AMP posts in a browser, right-click > View Page Source.
  • Search for rel="canonical" and <title>—look for duplicate entries, and note any differences in the URL or text (this can hint at whether it’s your SEO plugin, AMP plugin, or theme adding the extra tag).
  • For WordPress sites, you can also use the Query Monitor plugin to see which hooks are firing to add these tags (look for hooks like wp_head or amp_post_template_head).
2. Adjust Hook Priorities (Your Most Likely Fix)

If your previous hook attempts failed, it’s almost certainly a priority issue. SEO plugins often use very early hook priorities (like 1) to inject their tags, while default hooks run at 10. To override this, use a lower priority number to remove the duplicate before it loads, or a higher number to clean up after:

Example for Removing a Duplicate Canonical (Yoast SEO + AMP Plugin):

add_action( 'wp_head', function() {
    // Remove Yoast's canonical from AMP pages
    if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
        remove_action( 'wp_head', 'wpseo_canonical', 1 );
    }
}, 0 ); // Runs before Yoast's hook (priority 1)

Example for Removing a Duplicate Title (Rank Math + AMP Plugin):

add_action( 'amp_post_template_head', function() {
    // Remove Rank Math's title from AMP template head
    remove_action( 'amp_post_template_head', 'rank_math/frontend/title', 5 );
}, 1 ); // Runs before Rank Math's AMP hook

Pro tip: Use your SEO plugin’s documentation to find the exact function name and priority it uses for AMP tags.

3. Use AMP-Specific Hooks Instead of Global Ones

AMP pages don’t always respect standard wp_head hooks—they use their own template hooks like amp_post_template_head. If you were using global hooks before, switch to AMP-specific ones to target only AMP content:

// Remove duplicate canonical from AMP template head
add_action( 'amp_post_template_head', function() {
    // Replace with your SEO plugin's canonical function
    remove_action( 'amp_post_template_head', 'your_seo_plugin_amp_canonical', 5 );
}, 1 );
4. Disable Conflicting AMP Integrations

Most SEO plugins (Yoast, Rank Math, etc.) have built-in AMP support that can clash with standalone AMP plugins. Try this:

  • Go to your SEO plugin’s settings, find the AMP tab, and disable its AMP integration.
  • Let your standalone AMP plugin handle the AMP markup, and configure it to pull canonical/title data from your SEO plugin (look for settings like "Use SEO Plugin Metadata").
5. Filter AMP Output Directly (Last Resort)

If all else fails, you can directly edit the AMP page’s HTML to remove duplicates. Use a filter to scan and clean up the head content:

Safe DOM-Based Approach (Avoids Regex Errors):

add_filter( 'amp_post_template_head', function( $head_content ) {
    libxml_use_internal_errors( true ); // Suppress HTML parsing warnings
    $dom = new DOMDocument();
    $dom->loadHTML( '<html><head>' . $head_content . '</head></html>' );
    libxml_clear_errors();

    // Remove extra canonical links (keep only the first one)
    $canonicals = $dom->getElementsByTagName( 'link' );
    $keep_canonical = true;
    for ( $i = $canonicals->length - 1; $i >= 0; $i-- ) {
        $link = $canonicals->item( $i );
        if ( $link->getAttribute( 'rel' ) === 'canonical' ) {
            if ( !$keep_canonical ) {
                $link->parentNode->removeChild( $link );
            }
            $keep_canonical = false;
        }
    }

    // Remove extra title tags (keep only the first one)
    $titles = $dom->getElementsByTagName( 'title' );
    $keep_title = true;
    for ( $i = $titles->length - 1; $i >= 0; $i-- ) {
        $title = $titles->item( $i );
        if ( !$keep_title ) {
            $title->parentNode->removeChild( $title );
        }
        $keep_title = false;
    }

    return str_replace( array( '<html><head>', '</head></html>' ), '', $dom->saveHTML() );
}, 9999 ); // Run after all other head content is added
6. Test for Theme Conflicts

Some themes inject their own canonical/title tags regardless of AMP. Temporarily switch to a default WordPress theme (like Twenty Twenty-Four) and check if the duplicates disappear. If they do, add a similar hook to remove your theme’s AMP-unfriendly tags.

After trying any fix, use Google’s AMP validation tool to verify your page is valid and free of duplicate tags.

内容的提问来源于stack exchange,提问作者Hansjörg Leichsenring

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:04:15