alexkras.com

  • Home
  • Top Posts
  • Resume
  • Projects
  • YouTube
  • Boots to Bytes
  • About
  • Contact

How to Disable AMP on WordPress

June 26, 2017 by Alex Kras 22 Comments

Few days ago I disabled AMP support on my site.

To disable AMP support, I took the following steps.

  1. Log in to my WordPress dashboard
  2. Go to Plugins -> Installed Plugins
  3. Find “AMP” plugin
  4. Click “Deactivate” link under the AMP plugin
  5. Click “Delete” link under the AMP plugin

That is all I had to do, and 24 hours later AMP link to my site was gone from Google Search Results.

The only issue I noticed is that old AMP links were now returning a 404 – Page Not Found message.


For example:

https://www.alexkras.com/my-history-with-web-development-or-javascript-fatigue/amp would return 404 since there was no longer a /amp version of the link.

Redirect All 404s to Homepage

To remedy this issue, I’ve downloaded the All 404 Redirect to Homepage

  1. In WordPress dashboard
  2. Go to Plugins -> Add New
  3. In top right corner search for “All 404 Redirect to Homepage”
  4. Click “Install Now” button for the first result
  5. Click “Activate” button for the first result

As the name of plugin suggests, it will redirect all 404 to the home page. I already have a list of all post on my homepage rendered, via Clean My Archives plugin, so it was a decent solution in and of itself.

Redirect All AMP links to non AMP version

I wanted to take it one step further, though, so I modified the plugin to re-write AMP links to non amp version.

The steps to do so were as follows:

  1. In WordPress dashboard
  2. Go to Plugins -> Editor
  3. In top right drop down select “All 404 Redirect to Homepage” and click select
  4. It should open the all-404-redirect-to-homepage/all-404-redirect-to-homepage.php file for editing
  5. In it find if($options['p404_status']=='1' & $options['p404_redirect_to']!=''){ line
  6. Copy paste the following code right bellow it (and indent it one tab extra so it looks readable)
  7. Click “Update File” link right at the top left corner
if (strpos($link, "/amp") !== false) {
    header ('HTTP/1.1 301 Moved Permanently');
    header ("Location: " . str_replace('/amp', '', $link));
    exit();
}

It should look as the following image:

Finally, test it by navigating to an /amp version of any page on your site (after you’ve disabled AMP) to confirm that the redirect worked.

I am planning to write a proper WordPress plugin and publish it on Github, if there is interest. Please follow me on Twitter if you would like to hear more or DM me if you’d like to participate.

For now I wanted to share this quick hack as a stop-gap solution, until the proper plugin can be developed.


Filed Under: AMP, SEO

After graduating from Front-End and React Nanodegrees from #Udacity, last week I graduated from the #FullStack Nanodegree.

I'm now looking for my next role as #FullStack Developer. I've experience working with JS (React, Redux, Node), and Python.#WomenWhoCode #WomenInTech

— Shajia Abidi (@abidishajia) February 13, 2019

You can find me on LinkedIn, GitHub, Twitter or Facebook.

Subscribe to this Blog via Email

New posts only. No other messages will be sent.

Affiliates

  • Apixio, Medical Startup I work for is Hiring: https://grnh.se/49e0618a2
  • Checkout Hired, if Apixio is not for you: https://hired.com/x/YjFDXP
  • Programming Interviews Exposed or anything else from Amazon: https://amzn.to/2VDTSzC
  • Linode, where this site is hosted: https://www.linode.com/?r=0c6b1d50096034351b7feb80d175d7e315cc9a96
  • BlueHost, if you don’t want to manage your own server: https://www.bluehost.com/track/akras14/
  • Coinbase, if you are into Cryptocurrency https://www.coinbase.com/join/59c3348a22766100f93d9662

Recent Post

  • One Year Without Self-Promotion January 8, 2019
  • Group Log Data by Timestamp in Python with Pandas December 23, 2018
  • Attach Remote Debugger to Jar File and Scala REPL December 15, 2018
  • How to Rollback WordPress 5 to older version December 6, 2018
  • Adding Ammonite REPL to Scala For Ad Hoc Testing November 13, 2018

Comments

    Leave a Reply Cancel reply

  1. Dheeraj Kumar IELTS says

    September 17, 2018 at 11:51 pm

    Going to try this method.

    Reply
  2. Heartofcodes says

    July 12, 2018 at 10:59 am

    Thanks! the plugin method worked perfectly. I edited the plugin and it is redirecting amp to non amp.

    Reply
  3. Karen Woodham says

    May 5, 2018 at 3:45 am

    Brilliant, just what I was looking for, I was getting fed up of AMP causing a big issue with bounce rate, plus recently AMP wasn’t rendering, so I was getting 500 errors when the site was getting hits from Twitter on mobile. So thanks for the help, it’s worked a charm.

    Reply
  4. Jack The Dreamer says

    March 31, 2018 at 9:50 am

    Thank you for this! Looking to try it out because I noticed all of my blog’s posts on twitter were kept in AMP which didn’t show a lot of the features I had on the site.

    Reply
  5. A keen reader says

    March 7, 2018 at 9:41 am

    Such an excellent example of a fine blog post. Useful instructions, easy to follow and the solution works like a dream. Thank you, thank you, thank you for posting this.

    Reply
  6. Nitish Pradhan says

    January 26, 2018 at 2:04 am

    o My God thanks a lot it worked perfectly on my website.

    Reply
  7. Abhijeet Pratap says

    January 24, 2018 at 10:26 pm

    Thanks! the plugin method worked perfectly. I edited the plugin and it is redirecting amp to non amp.

    Reply
  8. Joe says

    December 23, 2017 at 10:32 am

    If you are using SEO plugin Yoast just enter this fix in the redirection section of the plugin.

    Keep source /(.*)\/amp
    Target URL https://www.yourdomain.com/$1

    No need for extra plugin.

    Reply
  9. Pascal says

    December 11, 2017 at 10:09 pm

    Hi
    Instead of using a plugin, use .htacess:

    Redirect from AMP to non-AMP path

    RewriteEngine On
    RewriteCond %{REQUEST_URI} (.+)/amp(.*)$
    RewriteRule ^ %1/ [R=301,L]

    Reply
  10. Agung Rangga says

    October 29, 2017 at 7:33 pm

    Thank you. This method is worked for me. 🙂

    Reply
  11. anapiazzajoias says

    October 18, 2017 at 8:14 am

    Hi there! I have removed AMP from my plugins. My website is quite new so there are no /amp/ links floating online.
    I am trying now to post a new link to twitter and it still automatically add /amp/ to the end of my link… Do you know of a way to make it stop?
    Thank you for the article – I thought I was the only that did not link AMP.

    Reply
    • Alex Kras says

      October 18, 2017 at 8:17 am

      Hmm, if you have disabled AMP plugin, and it’s still happening. My guess is Twitter cached your site as “AMP enabled”. I would still implement redirect plugin outlined above and it should fix the issue.

      Reply
  12. FilmyTech says

    October 4, 2017 at 12:10 am

    Usd this method and let me see if it works.Anyways, great post

    Reply
  13. mallorcaguidese says

    September 18, 2017 at 11:46 am

    Worked like a charm! Thanks for a great guide on how to disable AMP on WordPress.

    Reply
  14. Rumahdev.com says

    September 14, 2017 at 8:59 pm

    Thanks Its Work

    Reply
  15. getbigideablog says

    September 14, 2017 at 5:24 am

    worked for me thanks alot

    Reply
  16. Faheem ALi says

    September 4, 2017 at 8:41 am

    amazing waiting for AMP to be Removed From Search Engine

    Reply
  17. Nella Murazik says

    August 23, 2017 at 1:54 am

    Thank you for helping! Your script save me a lot of time!

    Reply
  18. nadia mansor says

    July 29, 2017 at 11:48 pm

    thanks !!! help me a lot!

    Reply
  19. loup20 says

    July 27, 2017 at 1:41 pm

    amazing!!

    Reply
  20. Emi says

    July 27, 2017 at 8:55 am

    Thanks, that worked perfectly on my site.

    Reply
  21. mattquirk says

    June 30, 2017 at 4:53 pm

    Hey Alex, loved the article about why you chose to turn AMP off. I’ve never liked the idea of AMP for many of the same reasons you cite here. I’m heavily into the marketing side of the industry now and see the movement towards AMP as a slight against our industry.

    As you said, why not rely on responsive Web practices like you demonstrated and try to minimize JS so our sites work on more browsers and devices and connections world wide?

    Reply

Copyright © 2019 · eleven40 Pro Theme on Genesis Framework · WordPress · Log in