AMP reporting many errors
-
I have sent the data to you. The resulting Support UUID is ampwp-89ce343a-bdf0-58cd-b8d9-c81998062645 The most serious problem is the fact that my theme GeneratePress in not compatible with AMP. However I cannot change the theme since I made too many necessary changes to it over the years. Hope you can help me out and thanks!
The page I need help with: [log in to see the link]
-
I have posted in the GeneratePress WP support forum and the problem was not resolved. I have emailed the author of GeneratePress several times and there was no reply.
Hello @richard1250
Thank you for creating a support topic, GenratePress can be made AMP-compatible using a small plugin they created.
We checked your support data it seems you are using the child theme of GeneratePress. which created a validation error.
The source of error seems to be
functions.phpfile with the functionadd_twitter_cardsfunction having an invalid attribute.I will recommend checking twitter cards tags one more time from the official documentation and validate once added on twitter card validator
Another error about Generatepress adding script should be fixed by AMP for the GeneratePress plugin.
if that didn’t help, please add the following code to the child themes functions.php file.
add_filter( 'generate_print_a11y_script', 'amp_remove_a11y_script' ); /** * Remove the a11y script from GeneratePress. * * @param bool $print Whether to print the script or not. */ function amp_remove_a11y_script( $print ) { if ( function_exists( 'amp_is_request' ) && amp_is_request() ) { return false; } return $print; }Hope this helps!
Hi Milind
This is my Twitter card code in functions.php and I have no idea what’s wrong with it:
<meta name=”twitter:card” value=”summary_large_image” />
<meta name=”twitter:title” value=”<?php echo $tc_title; ?>” />
<?php if($tc_image) { ?>
<meta name=”twitter:image” value=”<?php echo $tc_image_thumb; ?>” />Then the code you send me is not accepted by the file editor in WP. Any idea?
Thank you so much!
Best regards
RichardHello @richard1250
Sorry for the delayed response, it seems you are using
valueattribute while the Twitter docs mentioncontentattributeCan you please try the below code also please replace variable values for
$tc_title,$tc_exceprtand$tc_image_thumbwith yours values.add_action( 'wp_head', function() { $tc_title = get_the_title(); $tc_exceprt = strip_tags( get_the_excerpt() ); $tc_image_thumb = 'http://graphics8.nytimes.com/images/2012/02/19/us/19whitney-span/19whitney-span-articleLarge.jpg'; ?> <meta name="twitter:card" content="summary_large_image"> <meta name="twitter:creator" content="@RichardDetering"> <?php if ( ! empty( $tc_title ) ) { ?> <meta name="twitter:title" content="<?php echo esc_attr( $tc_title ); ?>"> <?php } ?> <?php if ( ! empty( $tc_exceprt ) ) { ?> <meta name="twitter:description" content="<?php echo esc_attr( $tc_exceprt ); ?>"> <?php } ?> <?php if ( ! empty( $tc_image_thumb ) ) { ?> <meta name="twitter:image" content="<?php echo esc_attr( $tc_image_thumb ); ?>"> <?php } } );The same code worked for me on my test site, also verified same on twitter card validator
Hope this helps!
Thanks Milind! Question: “Replace variable values for $tc_title, $tc_exceprt and $tc_image_thumb with your values.
As far as I know these values are not variable or am I wrong?
Have unfortunately no idea what to replace them with. Do you know where I can find these values?Sorry for the confusion, I mean the variables (the ones you were using before), it’s up to you how you wanted to use Twitter cards (you easily find examples of Twitter cards by quick search)
Sorry Milind, am not a developer and I still don’t understand. Example the URL you gave me http://graphics8.nytimes.com/images/2012/02/19/us/19whitney-span/19whitney-span-articleLarge.jpg in your coding should be replaced with what? Further $tc_title, and $tc_exceprt in your coding seem OK for me so they don’t need to be replaced I suppose? Sorry for my ignorance.
No problem Richard, I thought you have those variables that might be getting values from somewhere in your code snippet.
In case no, then please use the updated code snippet below that uses the post’s feature image for the Twitter card.
You also need a default image path (currently it’s your image) if the post has no feature image set.
add_action( 'wp_head', function() { $tc_title = get_the_title(); $tc_exceprt = strip_tags( get_the_excerpt() ); $tc_image_thumb = has_post_thumbnail() ? get_the_post_thumbnail_url() : 'https://richarddetering.com/wp-content/uploads/2020/01/richarddetering8.jpg'; ?> <meta name="twitter:card" content="summary_large_image"> <meta name="twitter:creator" content="@RichardDetering"> <?php if ( ! empty( $tc_title ) ) { ?> <meta name="twitter:title" content="<?php echo esc_attr( $tc_title ); ?>"> <?php } ?> <?php if ( ! empty( $tc_exceprt ) ) { ?> <meta name="twitter:description" content="<?php echo esc_attr( $tc_exceprt ); ?>"> <?php } ?> <?php if ( ! empty( $tc_image_thumb ) ) { ?> <meta name="twitter:image" content="<?php echo esc_attr( $tc_image_thumb ); ?>"> <?php } } );replace the previous code snippet with this one
Great and thanks Milind!
Great job Milind. The Twitter card works perfect and the error about the Child Theme disappeared. The only compatibility error still popping up is the one about GeneratePress which is the theme the child theme is based on. Is that a problem or can I ignore it? (By the way, it’s funny that you write exceprt in stead of excerpt in the coding).
@richard1250
You can ignore that error, it should not be a problem, Ha I just noticed that exceprt!! πThanks for your professional help. Highly appreciated!
The topic ‘AMP reporting many errors’ is closed to new replies.