Clicky

  1. Home
  2. Developer Docs
  3. General
  4. How to detect if it’s AMP page with Function?

How to detect if it’s AMP page with Function?

If you are developing some code and you want to detect if it’s AMP then you can use the below code.

if ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) {
}

Warning: is_amp_endpoint() is depreciated from AMPforWP

If you are facing any warnings in the debug log or on the website like

Notice: is_amp_endpoint was called <strong>incorrectly</strong>. is_amp_endpoint() is deprecated from AMPforWP, please use ampforwp_is_amp_endpoint instead. Please see <a href=”https://codex.wordpress.org/Debugging_in_WordPress”>Debugging in WordPress</a> for more information.

Then to solve this warning, go to the path mentioned in the warning and  find is_amp_endpoint and replace it with ampforwp_is_amp_endpoint

This will fix the warnings.

Hope it helps. If you have any questions, then please ask us in the below comments.

Ask your Questions Directly!
If you can't find the solutions in this article, then just ask us in the comments and we will answer it for you!
Updated on May 7, 2020

    Are you still looking for a solution?

    Then fill out the below form and we will reach out to you within a few hours.

    Was this article helpful?

    Related Articles

    Comments

    1. Hello, I have the following error message on my website (this page for example : https://radinmalinblog.com/5-astuces-efficaces-pour-remplacer-le-sopalin )

      Notice: is_amp_endpoint est appelée de la mauvaise manière. is_amp_endpoint() is deprecated from AMPforWP, please use ampforwp_is_amp_endpoint instead. Check https://ampforwp.com/tutorials/article/detect-amp-page-function/ for more info Veuillez lire Débogage dans WordPress (en) pour plus d’informations. (Ce message a été ajouté à la version 5.1.1.) in /homepages/37/d574216427/htdocs/clickandbuilds/WordPress/MyCMS2/wp-includes/functions.php on line 4667

      Problem is, on functions.php there is no mention of ampforwp either at line 4667 nor in the rest of the document. Thus, I couldn’t find is_amp_endpoint and replace it with ampforwp_is_amp_endpoint as you instructed in your help section.

      This happened after I updated to WP 5.1.1
      I have de-activated the plug-in AMP for WP for the moment.

      Thank you!

    2. if ( function_exists( ‘ampforwp_is_amp_endpoint’ ) && ampforwp_is_amp_endpoint() ) {

      }

      this code does not work… crashes WordPress..

    Leave a Comment