• gundemden

    (@gundemden)


    Hello,

    I have been receiving the “Alternative page with the correct standard tag” error for a very long time. There are many other errors in Search Console, but specifically due to the ‘hreflang‘ tag, my content is no longer getting indexed, and my ranking has almost disappeared. There is no issue with the hreflang tag on the web version, but even if there is a canonical URL in the AMP version, the Search Console source code indicates that it wants to see the ‘hreflang’ tag for multilingual websites.

    I am using the Polylang plugin because I am using WordPress. How can I overcome this issue? I have a website in approximately 40 languages, and I want to display the hreflang tag in my AMP posts or pages. How can I do this? Can you help me?

    I shared a sample URL, but I am experiencing the same issue on all AMP pages, not just that one. I checked the topics in this forum, and since there wasn’t a similar topic, I decided to start this thread to seek help.

    • This topic was modified 2 weeks ago by gundemden.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter gundemden

    (@gundemden)

    can you hear me anyone?

    Plugin Support Milind More

    (@milindmore22)

    Hello @gundemden

    Thank you for reaching out to us, Yes hreflang attribute was not being added to link tags added by AMP plugin, can you please try adding the following code snippet at end of your child themes function.php file

    /**
     * Add amphtml link.
     *
     * @since 1.0
     */
    function amp_add_amphtml_link_hreflang() {
    	if ( function_exists( 'amp_is_canonical' ) && ! amp_is_canonical() ) {
    		$amp_url = amp_add_paired_endpoint( amp_get_current_url() );
    		// Get the locale code.
    		$locale_code = get_locale();
    		// Covert to ISO 639-1 language code.
    		$locale_code = substr( $locale_code, 0, 2 );
    		
    		// ploylang support.
    		if( function_exists( 'pll_current_language' ) ) {
    			$locale_code = pll_current_language('slug');
    		}
    
    		if ( $amp_url ) {
    			$amp_url          = remove_query_arg( 'noamp', $amp_url );
    			printf( '<link rel="amphtml" href="%s" hreflang="%s">', esc_url( $amp_url ), $locale_code );
    		}
    	}
    }
    
    add_action( 'wp_head', 'amp_add_amphtml_link_hreflang' );
    
    add_action( 'template_redirect', static function () {
     	remove_action( 'wp_head', 'amp_add_amphtml_link' );
    } );
    
    

    Please try above code and let me know if that works for you

    Thread Starter gundemden

    (@gundemden)

    After adding the code you specified to the page in my Hello Elementor theme, I was unable to access my website, and it displayed the following error: “There is a critical issue with your site.”

    This issue persisted until I removed the code. I pasted the code exactly as you provided it, without making any changes. My website is experiencing serious problems, and all error pages seem to originate from AMP. To resolve this, I need to add hreflang tags to the AMP pages, as my site supports 45 languages. A year ago, I had over a million monthly visitors, but now it’s not even reaching 10,000. My rankings have dropped significantly due to these errors.

    Thread Starter gundemden

    (@gundemden)

    Update: I made a mistake somewhere. I added the code, and the website is now accessible, but when I look at the source code of the AMP posts, I still don’t see the hreflang tags. Bknz: code:

    • This reply was modified 1 week, 2 days ago by gundemden.
    Plugin Support Milind More

    (@milindmore22)

    Hello @gundemden

    Can you please check the updated code snippet, replace with previous code snippet

    Please add the code snippet in child themes functions.php or in a custom plugin.

    /**
     * Add amphtml link.
     *
     * @since 1.0
     */
    function amp_add_amphtml_link_hreflang() {
    	if ( function_exists( 'amp_is_canonical' ) && ! amp_is_canonical() ) {
    		$amp_url = amp_add_paired_endpoint( amp_get_current_url() );
    		// Get the locale code.
    		$locale_code = get_locale();
    		// Covert to ISO 639-1 language code.
    		$locale_code = substr( $locale_code, 0, 2 );
    		
    		// ploylang support.
    		if( function_exists( 'pll_current_language' ) ) {
    			$locale_code = pll_current_language('slug');
    		}
    
    		if ( $amp_url ) {
    			$amp_url          = remove_query_arg( 'noamp', $amp_url );
    			printf( '<link rel="amphtml" href="%s" hreflang="%s">', esc_url( $amp_url ), $locale_code );
    		}
    
    		if ( function_exists( 'pll_the_languages' ) ) {
    			$languages = pll_the_languages( array( 'raw' => 1 ) );
    			foreach ( $languages as $language ) {
    				$href = $language['url'];
    				$href = amp_add_paired_endpoint( $href );
    				$href = remove_query_arg( 'noamp', $href );
    				printf( '<link rel="alternate" href="%s" hreflang="%s" />', esc_url( $href ), esc_attr( $language['slug'] ) );
    			}
    		}
    	}
    }
    
    add_action( 'wp_head', 'amp_add_amphtml_link_hreflang' );
    
    add_action( 'template_redirect', static function () {
     	remove_action( 'wp_head', 'amp_add_amphtml_link' );
    } );
    
    add_action( 'amp_post_template_head', 'add_polylang_alternate_links' );
    
    /**
     * Add alternate links for Polylang.
     *
     * @return void
     */
    function add_polylang_alternate_links() {
    	if ( function_exists( 'pll_the_languages' ) ) {
    		$languages = pll_the_languages( array( 'raw' => 1 ) );
    		foreach ( $languages as $language ) {
    			$href = $language['url'];
    			$href = amp_add_paired_endpoint( $href );
    			$href = remove_query_arg( 'noamp', $href );
    			printf( '<link rel="alternate" href="%s" hreflang="%s" />', esc_url( $href ), esc_attr( $language['slug'] ) );
    		}
    	}
    }
    Thread Starter gundemden

    (@gundemden)

    Hello,

    I added the code you provided to the functions page of my theme, but, as you can see in the attached file (error), serious problems occurred. Afterward, I added it to the Functions.

    PHP of the AMP plugin, but I started encountering the problems you’ll see in the attached ‘error3’ file.

    When I added the code, hreflang-related information appeared, but it looked like this:

    </script><link rel="alternate" hreflang="tr"><link rel="alternate" hreflang="en"><link rel="alternate" hreflang="de"><link rel="alternate" hreflang="it"><link rel="alternate" hreflang="es"><link rel="alternate" hreflang="fr"><link rel="alternate" hreflang="az"><link rel="alternate" hreflang="pt"><link rel="alternate" hreflang="el"><link rel="alternate" hreflang="bg"><link rel="alternate" hreflang="ru"><link rel="alternate" hreflang="fa"><link rel="alternate" hreflang="he"><link rel="alternate" hreflang="nl"><link rel="alternate" hreflang="ar"><link rel="alternate" hreflang="zh"><link rel="alternate" hreflang="kk"><link rel="alternate" hreflang="pl"><link rel="alternate" hreflang="hi"><link rel="alternate" hreflang="ro"><link rel="alternate" hreflang="nn"><link rel="alternate" hreflang="fi"><link rel="alternate" hreflang="sv"><link rel="alternate" hreflang="uk"><link rel="alternate" hreflang="sr"><link rel="alternate" hreflang="cs"><link rel="alternate" hreflang="hu"><link rel="alternate" hreflang="hr"><link rel="alternate" hreflang="sk"><link rel="alternate" hreflang="ms"><link rel="alternate" hreflang="ja"><link rel="alternate" hreflang="bn"><link rel="alternate" hreflang="skr"><link rel="alternate" hreflang="ko"><link rel="alternate" hreflang="au"><link rel="alternate" hreflang="uz"><link rel="alternate" hreflang="id"><link rel="alternate" hreflang="da"><link rel="canonical" ><title>BigBag ?uval ?hracat? ?thalat? Toptan Big Bag Sat?c?lar?</title><style id="admin-bar-inline-css" type="text/css" data-ampdevmode="">

    The ampdevmode appears, which is seen as an error by the AMP validator. I’m really tired of this error, could you please help me?

    Thread Starter gundemden

    (@gundemden)

    This project is a 5-year-old project, and unfortunately, due to AMP errors, it has been ruined. I have been trying to fix this issue for a year, and I have tried every possible method. I changed the theme, hired a developer, switched hosting. I wiped everything and re-uploaded just my posts, pages, etc., with a fresh database, but the issue still wasn’t resolved. I’ve tried everything, but there is no solution. The Google Search Console errors are increasing every day, and the problems are never fixed.

    Plugin Support Milind More

    (@milindmore22)

    Hello @gundemden

    I genuinely understand your frustration. It’s disheartening to invest significant time and effort into a project, only to be met with persistent issues. AMP errors can be particularly challenging to troubleshoot, especially when standard solutions don’t yield results.

    The solution which I provided is based on the AMP Internationalization guideline and example

    <style id="admin-bar-inline-css" type="text/css" data-ampdevmode="">

    The data-ampdevmode attribute is added to the Admin bar, that should only be visible to logged-in users. If you’re seeing it while logged out, it suggests a caching issue. To resolve this, please flush your site’s cache.

    Since you are using Elementor, I will recommend using the AMP Enhancer plugin, which adds compatibility for some third-party plugins and themes such as Elementor.

    We hope this helps!

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.