Referenced AMP URL is self-canonical AMP

#240273
  • Resolved Sufiyan Momin
    Rank Math free

    Hello team

    Google Search Console is showing an error for most of my AMP URLs as Referenced AMP URL is self-canonical AMP.

    I tried to check the source code of the page and it’s referring to itself,

    once I disable amp from the rankmath dashboard, it shows the correct URL, but enabling AMP in the dashboard is causing this issue.

    Kindly help with this please….

Viewing 9 replies - 1 through 9 (of 9 total)
  • This seems to fix the issue:

    add_action( 'rank_math/frontend/canonical', function( $url ) {
    	if ( ! is_singular() || ! function_exists( 'better_amp_rel_canonical_url' ) ) {
    		return $url;
    	}
    
    	$custom_url = RankMath\Post::get_meta( 'canonical_url', get_the_ID() );
    	if ( $custom_url ) {
    		return $custom_url;
    	}
    
    	return better_amp_rel_canonical_url();
    });

    Can you guys fix this parmanently?

    Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for the delay and for any inconvenience this issue may have caused you.

    Unfortunately, we were not able to provide a permanent solution for that since the plugin has been banned from WordPress due to policy violations.

    Here’s a link for more information:
    https://wordpress.org/plugins/better-amp/

    I hope that helps.

    Thank you, and please don’t hesitate to contact us anytime if you need further assistance with anything else.

    Hello Team,

    The below code is working fine for Posts, but can you please help to make it work for categories as well?

    As I’m getting the same error only for category pages…

    add_action( 'rank_math/frontend/canonical', function( $url ) {
    	if ( ! is_singular() || ! function_exists( 'better_amp_rel_canonical_url' ) ) {
    		return $url;
    	}
    
    	$custom_url = RankMath\Post::get_meta( 'canonical_url', get_the_ID() );
    	if ( $custom_url ) {
    		return $custom_url;
    	}
    
    	return better_amp_rel_canonical_url();
    });

    Hello,

    Please try using this filter instead to apply to your category pages as well:

    add_action( 'rank_math/frontend/canonical', function( $url ) {
    	if ( ! function_exists( 'better_amp_rel_canonical_url' ) ) {
    		return $url;
    	}
    
    	$custom_url = RankMath\Post::get_meta( 'canonical_url', get_the_ID() );
    	if ( $custom_url ) {
    		return $custom_url;
    	}
    
    	return better_amp_rel_canonical_url();
    });

    If it’s still not working, you can try this one:

    add_action( 'rank_math/frontend/canonical', function( $url ) {
    	$custom_url = RankMath\Post::get_meta( 'canonical_url', get_the_ID() );
    	if ( $custom_url ) {
    		return $custom_url;
    	}
    	return better_amp_guess_none_amp_url();;
    });

    I hope that helps.

    Thank you.

    will this work for both, post and categories?

    Hello,

    Yes, the code will work for all post types and categories on your site. Please replace the previous code with the one provided by my colleague and check if this resolves the issue or not.

    Let us know how that goes. Looking forward to hearing from you.

    Sorry for the late response.

    I want to confirm it works before I tell you anything…

    The code seems to be working as expected and we can consider this issue resolved.

    Thanks a lot team.

    Hello,

    Thank you for the update.

    We are super happy that this issue is already resolved. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind us asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 9 replies - 1 through 9 (of 9 total)

The ticket ‘Referenced AMP URL is self-canonical AMP’ is closed to new replies.