Support » Fixing WordPress » Help Coding a Small Snippet to Solve a Bug

  • Hi all,

    I’m using the plugin AMP Woocommerce But, unfortunately the plugin has a long time bug that blocks Google from indexing Woocommerce AMP pages. It is a simple viewport meta tag missing from the header of AMP pages.

    It is an easily solvable problem but the developer doesn’t seem to care. I just need a bit of assistance in coding a php snippet for my site since my coding knowledge is limited. A more detailed description of the problem is this:

    When checking the Woocommerce AMP pages in validator.ampproject.org it returns:
    “The mandatory tag ‘meta name=viewport’ is missing or incorrect.”
    I’m trying to code a snippet shown below to add the “meta name” html bit to the header of ONLY my AMP Woocommerce pages.

    For that, I’ve used an if and the function is_product() but it doesn’t recognize Woocommerce AMP pages as products. I can’t delete the is_product() and apply the snippet everywhere since it duplicates the meta tag on non-woocommerce AMP pages. Any suggestion on getting it to work ONLY there? (note that I’m using Astra theme). (I’ve also tried is_woocommerce()).

    I’ve thought about adding something similar to: if (inurl()==”amp” || not==”<meta name=”viewport”>”) but don’t know how to do it properly.

    if (is_product()) {
        function astra_amp_add_viewport() { ?>
    	<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
        <?php }
    }
    add_action( 'amp_post_template_head', 'astra_amp_add_viewport' ); 
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Steve Stern

    (@sterndata)

    Support Team Volunteer

    You could try “is_woocommerce()” or “is_page_template()” instead.

    Thanks @sterndata,

    Unfortunately, as I mentioned, I tried is_woocommerce to no avail as well.

    I’ve tried to use is_page_template() but couldn’t make it work. Can you help me check if this if has been correctly coded?

    The plugin uses three templates with the path written in the code below. I’ve used all three with OR in the if statement but still getting no meta tag in AMP product pages.

    if (is_page_template('wp-content/plugins/amp-woocommerce/templates/design2-wc.php') || is_page_template('wp-content/plugins/amp-woocommerce/templates/design3-wc.php') || is_page_template('wp-content/plugins/amp-woocommerce/templates/wc.php')) {
    	function astra_amp_add_viewport() { ?>
    		<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
    	<?php }
    }
    add_action( 'amp_post_template_head', 'astra_amp_add_viewport' );

    I’ve tried the same if using the path: ‘templates/design2-wc.php’ with no success. I’ve read some of the plugin’s code and it uses only those 3 templates. Don’t know why it doesn’t work. And unfortunately, after 4 days, the developer still doesn’t answer.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Help Coding a Small Snippet to Solve a Bug’ is closed to new replies.