I'm using Gatsby and would like have my website identified an AMP website .
How do I add the mandatory AMP attribute to the <html>
tag?
In order to add the mandatory AMP HTML attribute to your <html>
tag using Gatsby, you may want to:
Customise your html.js
file by cloning the .cache/default-html.js
to your src/
directory.
You can achieve that by running the command line below;
cp .cache/default-html.js src/html.js
amp=""
to the newly created src/html.js
file as follows;<html amp="" {...props.htmlAttributes}>
Aside the option above, you can achieve same by simply adding the snippet below to your gatsby-ssr.js
file;
import React from "react"
// Adds an amp attribute to the <html> tag
export const onRenderBody = ({ setHtmlAttributes }) => {
setHtmlAttributes({
amp: ``,
})
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.