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' );
The topic ‘Help Coding a Small Snippet to Solve a Bug’ is closed to new replies.