Home >CMS Tutorial >WordPress >How to Use AMP with WordPress
Core points
The Google Accelerated Mobile Pages (AMP) project was launched on February 24, 2016. With this launch, thousands of developers became active participants in the project. Countless websites now have AMP version pages, and many developers are learning to use AMP – in this case, learn how to use AMP in WordPress.
Google attaches great importance to AMP. It is also one of their search engine ranking criteria. In this way, Google makes AMP a necessity for many websites. In this article, I will provide you with detailed information about Google's accelerated mobile page project. This includes the steps to call it in your WordPress site.
What is AMP?
Some developers may not be familiar with AMP. It is a mobile-friendly framework that quickly loads your web pages on a mobile browser. It is an open source technology designed to enable website publishers to effectively improve the speed and user experience of loading content pages on mobile devices. All these enhancements will not affect advertising revenue.
If you are an experienced developer, you can achieve similar enhancements with comprehensive page loading optimizations. However, accelerating mobile pages makes these optimizations very easy to perform without spending too much time and effort on mobile layouts.
For those sites that have redoubled their SEO rankings, this will certainly add more tasks on their to-do list, as the AMP page can also enhance your website's SEO rankings. This may be the main reason why large companies also adopt AMP.
AMP project
AMP contains three main components:
It is a subset of HTML with many limitations, custom tags, and custom properties. If you are already familiar with HTML, it is not complicated to adapt to this. However, if you find any difficulties, I recommend you visit this link to learn more about how to create your AMP HTML page.
AMP provides a limited number of JavaScript for mobile web pages. Now, one important thing to remember about JS in AMP is that AMP does not allow third-party JavaScript.
Google AMP Cache is a CDN used to deliver AMP pages. You all know the core features of the content delivery network – they distribute resources to servers closer to viewers of your website. For AMP pages, this CDN will allow for a minimum load time due to possible distance delays.
The correlation of AMP logo on SEO
Back in 2016, when Google launched AMP, AdAge.com published an interview with Richard Gingras, senior director of Google News and Social Products. In that interview, he said that the use of AMP will not be directly related to your search rankings because it is not a direct factor. He then added: "All other (search engine rankings) signals need to be met, too."
However, after this clarification, everything became clearer. He said: "If we have two articles, from a signal point of view, the same score on all other characteristics (except speed), then yes, we're going to focus on the fastest one, because that's the user Discover something eye-catching. ”
Even Google does not deny the relevance of AMP websites to SEO. Speed is always an influencing factor in search engine optimization. If AMP pages get more clicks and lower bounce rates due to faster loading, Google will surely rank the website higher for a better user experience.
How to AMP your website?You must maintain two versions of the article page on the website. Original article page, for default web users, and AMP version, for potential mobile users.
Also note that AMP does not allow form elements and third-party JavaScript. This means you can't put contact forms or in-page comments in the standard implementation, as AMP is primarily used for content delivery.
Yes, of course, Analytics works for AMP. In fact, Analytics on AMP is also smart. To prevent websites from slowing down due to multiple analytics trackers, they are based on the core philosophy of “one measurement, multiple reports”. Generally, there are two ways to enable Analytics for AMP on your website.
amp-pixel element: It is a simple tag that can use GET requests to calculate page views (similar to tracking pixels).
In fact, one of the easiest ways to use AMP is to implement it on your WordPress website. You can use the official plug-in developed by Automattic/WordPress.
Step 1: Install WordPress plugin
The Google search console will get the AMP version of the article page from the meta tag, which will be attached by the plugin. However, the problem is that it usually takes several days to detect such changes.
So, what should I do now? To handle these tricky situations, I recommend using a combination of Chrome verification process and search console. To use the Chrome verification process, please visit any of your AMP pages in Chrome. Then append #development=1 at the end of the URL. Now press Control Shift I to open Chrome Developer Tools.
Refresh the page and it will display "AMP verification successful" or provide a detailed list of issues that need to be fixed.
You can see that installing plugins is not enough. You must verify each data by accessing the page and repeating the above steps to benefit from accelerating mobile pages.
You have learned that verifying Schema tags is essential for your AMP page. I recommend using Google's structured data testing tool to test if your page has a valid schema tag. However, I found that WordPress has some problems with displaying the logo. So I made some modifications to overcome this.
Go to plug-in, click Editor, and select AMP. Change these lines in the editor to modify the plugin.
<code>if ( $site_icon_url ) { $metadata['publisher']['logo'] = array( '@type' => 'ImageObject', 'url' => $site_icon_url, 'height' => self::SITE_ICON_SIZE, 'width' => self::SITE_ICON_SIZE, ); }</code>
To:
<code>$metadata['publisher']['logo'] = array( '@type' => 'ImageObject', 'url' => 'http://yourdomain.com/wp-content/uploads/logo-company.png', 'height' => 60, 'width' => 170, );</code>
Make sure to specify the location of the logo in the URL and specify the height and width accordingly.
Now, you are almost done. However, I prefer to use Google Analytics to track statistics. The AMP WordPress plugin does not actively activate amp-analytics, but it is very easy to execute.
To enable the AMP WordPress plugin to work with Google Analytics, go to Plugins ->Editor ->Select "AMP" and add the following code to the end of it.
<code>add_action( 'amp_post_template_head', 'amp_post_template_add_analytics_js' ); function amp_post_template_add_analytics_js( $amp_template ) { $post_id = $amp_template->get( 'post_id' ); ?> async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js">> <?php } add_action( 'amp_post_template_footer', 'xyz_amp_add_analytics' ); function xyz_amp_add_analytics( $amp_template ) { $post_id = $amp_template->get( 'post_id' ); ?> <amp-analytics> type="googleanalytics" id="analytics1"></amp-analytics> type="application/json"> { "vars": { "account": "UA-XXXXX-Y" ←(YOUR GOOGLE ANALYTICS PROPERTY ID) }, "triggers": { "trackPageview": { "on": "visible", "request": "pageview" } } } > > <?php } </code>
Make sure to change the value UA-XXXXX-Y to your own Google Analytics property ID!
After making this change, reverify your AMP page and your AMP page will be trackable.
Conclusion on Google AMP Project
Google hopes that the AMP project will provide users with a good experience. Still, the question is whether AMP can make everything super fast. The answer to this question is quite open-ended. If you don't optimize your website well, AMP will bring some significant improvements.
However, speeding up mobile pages is not a magic bullet. Technology to improve website speed is provided from the outset. AMP is just trying to combine and eliminate all the major slow loading factors and provide users with better solutions.
What do you think of AMP projects? Please share your views in the comment section below!
FAQs about using AMP in WordPress (FAQ)
The main benefit of using AMP (accelerated mobile pages) with WordPress is the enhancement of the mobile browsing experience. AMP is a Google-backed project designed to make web pages load faster on mobile devices. It does this by streamlining HTML and using a thin version of CSS. This results in a significant increase in page loading speed, which can increase user engagement, retention and improve mobile SEO.
AMP can significantly improve your SEO because page loading speed is a ranking factor in Google's algorithm. By making your web pages load faster, AMP can help improve your visibility in search engine results, especially among mobile users. Additionally, Google typically highlights AMP pages in carousels highlighted in search results, providing further visibility.
Yes, you can use AMP on your existing WordPress website. There are several plugins available that can help you implement AMP on your WordPress website. These plugins help convert your existing posts and pages into AMP-compatible versions.
AMP limits certain HTML, CSS, and JavaScript elements to ensure fast page loading times. This means that some features of your WordPress website may not work as expected on the AMP version of your website. However, most AMP plugins offer options that can be added back to functionality by still complying with AMP standards.
CSS can be used to customize the appearance of AMP pages. However, since AMP restricts the use of certain CSS properties to ensure fast page load times, you may want to use a more streamlined approach to style it. Some WordPress AMP plugins offer built-in customization options.
You can use the AMP testing tool provided by Google to check whether your AMP implementation is successful. This tool will analyze your AMP page and report any errors that may prevent it from being provided as an AMP page in Google search results.
Yes, you can implement AMP without using plugins in WordPress, but this requires a good understanding of web development and AMP standards. You need to manually create a separate AMP-compatible version of your posts and pages and manually add the necessary AMP HTML tags.
Yes, AMP supports both advertising and analytics. However, because AMP restricts certain HTML, CSS, and JavaScript elements, you may need to use AMP-specific tags and scripts for advertising and analysis.
Yes, most WordPress AMP plugins offer options to disable AMP for a specific post or page. This is very useful if you have something that doesn't work well with AMP restrictions.
No, AMP is not a replacement for responsive design. While AMP can enhance the mobile browsing experience by making pages load faster, it does not replace the need to adapt to website designs of different screen sizes. It is best to use AMP in conjunction with responsive design for the best mobile user experience.
The above is the detailed content of How to Use AMP with WordPress. For more information, please follow other related articles on the PHP Chinese website!