# How to check if the current page is an AMP page

URL: https://wp24x7.com/how-to-check-if-the-current-page-is-an-amp-page-in-wordpress/
Updated: 2026-11-29
Type: blog post
Audience: WordPress theme developers using the official AMP plugin

> If your site uses the official AMP plugin, amp_is_request() tells you whether the current request is AMP. Wrap it in a function that checks the plugin exists, and call it only after the main query has run, for example in template files or on the wp action. This guide shows a guarded helper, an AMP-only sidebar and the common timing mistakes.

## Key facts

- For: theme developers branching markup for AMP and non-AMP requests
- Function: amp_is_request(), which replaces the deprecated is_amp_endpoint()
- Guard: function_exists() so deactivating the plugin does not cause a fatal error
- Timing: only after the query is parsed; not on init or plugins_loaded
- Modes: standard, transitional and reader behave differently
- Safety: back up and use a child theme or small plugin
- Help: theme development and WordPress development services

If your site uses the official AMP plugin, you sometimes need different markup for AMP and non-AMP requests, such as a simpler sidebar, no custom JavaScript or an AMP-safe ad. **The plugin gives you `amp_is_request()`. Wrap it in a function that checks the plugin exists, and call it only after the main query has run.**

> **Quick answer**
Use a guarded helper (`function_exists( 'amp_is_request' ) && amp_is_request()`) and call it in templates or on `wp` and later hooks, never on `init`. Back up first and use a child theme or small plugin.

## What is amp_is_request() and why guard it?

The AMP plugin provides `amp_is_request()`. It returns `true` when the current request is served as AMP, in any mode (standard, transitional or reader), and `false` otherwise. It replaced the deprecated `is_amp_endpoint()`.

If the plugin is deactivated, a direct call ends in a fatal error: "Call to undefined function". Wrap it:

```php
function mysite_is_amp(): bool {
	return function_exists( 'amp_is_request' ) && amp_is_request();
}
```

Use your own prefix instead of `mysite_` so the name cannot clash. The return type needs PHP 7 or later, which any supported WordPress already requires.

## When can I call it?

| Safe | Not safe |
|---|---|
| Template files such as `header.php`, `sidebar.php`, `single.php` | `plugins_loaded` |
| Callbacks on `wp`, `template_redirect`, `wp_head`, `wp_enqueue_scripts` and later | `after_setup_theme` |
| | `init` |

Calling it too early makes the AMP plugin log a "doing it wrong" notice, and the result may be unreliable. For example, to skip a script on AMP pages:

```php
add_action( 'wp_enqueue_scripts', function () {
	if ( mysite_is_amp() ) {
		return;
	}
	wp_enqueue_script( 'mysite-extras', get_stylesheet_directory_uri() . '/js/extras.js', array(), '1.0.0', true );
} );
```

Custom JavaScript is generally not allowed in AMP pages, so this keeps the page valid.

## What are the three AMP modes?

| Mode | How it works | Effect on `amp_is_request()` |
|---|---|---|
| Standard (AMP-first) | Every page is AMP, one version of the site | True on all front-end pages |
| Transitional | Each page has a normal and an AMP version at related URLs | True only on the AMP one |
| Reader | AMP versions use a separate, simplified template | Theme code mostly does not run there |

Check the mode in the AMP plugin's settings before you write anything.

## How do I vary the sidebar and template parts?

### AMP sidebar
Register a second sidebar so the AMP version only holds AMP-compatible widgets:

```php
add_action( 'widgets_init', function () {
	register_sidebar( array(
		'name'          => esc_html__( 'AMP Sidebar', 'mysite' ),
		'id'            => 'amp-sidebar',
		'description'   => esc_html__( 'Widgets shown on AMP pages only.', 'mysite' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
} );
```

Then in `sidebar.php`:

```php
<?php
$sidebar_id = mysite_is_amp() ? 'amp-sidebar' : 'sidebar-1';

if ( is_active_sidebar( $sidebar_id ) ) : ?>
	<aside class="sidebar">
		<?php dynamic_sidebar( $sidebar_id ); ?>
	</aside>
<?php endif; ?>
```

Replace `sidebar-1` with your theme's main sidebar ID, then add widgets under **Appearance, Widgets**. Block themes have no `sidebar.php`, so use template parts and conditional rendering instead.
### Template part
When a section such as a share bar needs a different file for AMP, use the second argument of `get_template_part()`:

```php
get_template_part( 'template-parts/share', mysite_is_amp() ? 'amp' : 'default' );
```

This loads `share-amp.php` or `share-default.php`. If a named file does not exist, WordPress falls back to `share.php`, so keep one of them.
### Other checks
- Add a body class: `add_filter( 'body_class', fn( $c ) => mysite_is_amp() ? array_merge( $c, array( 'is-amp' ) ) : $c );`.
- Skip ads or embeds that break AMP validity, or print an AMP-compatible alternative.
- Print analytics differently, since AMP uses its own component.

## How do I test it?

1. **Open a normal page and its AMP version.** In standard mode every page is AMP; in transitional or reader mode add `?amp=1` or use `/amp/`.
2. **Check the markup** has the expected sidebar.
3. **Check validity** under **AMP, Validated URLs** or the admin bar item.
4. **Check the normal page** is untouched.
5. **Deactivate the AMP plugin** and confirm the site works and the helper returns `false`.

## What mistakes are common?

- Calling `amp_is_request()` on `init` or `plugins_loaded` and getting a notice.
- Calling it without the `function_exists()` guard, then deactivating the plugin.
- Using the deprecated `is_amp_endpoint()`.
- Adding JavaScript to AMP pages, which fails validation.
- Testing only the normal page, and finding AMP errors in Search Console weeks later.
- Branching in the theme when a plugin, not the theme, loads the offending script.

## Do I need AMP at all, and what about caching?

AMP once gave a layout benefit in Google's mobile news carousel. In 2021 Google removed the AMP requirement for Top Stories, and page experience applies to any page. If normal pages already pass Core Web Vitals, a second version may cost more than it returns, so compare AMP and non-AMP traffic first. If you drop it, remove the plugin, redirect AMP URLs to the normal ones and clean up the branching code.

If a host or plugin caches pages, cache AMP and non-AMP separately. Page caches usually key on the URL, which is enough in transitional mode, but can go wrong if the same URL serves different markup. Clear the cache after deploying branching code and check both versions in a private window.

**AMP errors or retiring AMP?**
Our developers can fix validation or retire AMP without losing traffic.
[Post a project](/post-project)
[Theme development](/wordpress-theme-development)

For help see our [theme developers](/wordpress-theme-development) and [WordPress development team](/wordpress-development). For performance work that does not depend on AMP, see [fixing native lazy loading](/how-to-fix-native-lazy-loading-of-iframe-or-image-not-working).

## Frequently asked questions

### What function tells me if the current request is AMP?

amp_is_request(), provided by the official AMP plugin. Call it only after WordPress has parsed the query, for example inside template files or on the wp action.

### Why does amp_is_request() trigger a notice?

Calling it too early, such as at plugin load or on init, happens before WordPress knows which page is being requested, so the answer would be unreliable. Move the check later.

### Do I need to change my caching setup for AMP?

Make sure AMP and non-AMP versions are cached separately. In transitional or reader mode the URL differs, which usually keeps them apart, but clear caches after deploying code that branches on AMP.

### Do I still need AMP for Google rankings?

No. Google dropped AMP as a requirement for features like Top Stories in 2021. Keep AMP only if it still serves your readers or a partner.

### Why guard the call with function_exists()?

If the AMP plugin is deactivated or removed, a direct call ends in a fatal error: Call to undefined function. A guarded helper lets your theme survive without the plugin.

### What happened to is_amp_endpoint()?

It is deprecated and replaced by amp_is_request(). Avoid using it in new code.

### What are the three AMP modes?

Standard (AMP-first) serves every page as AMP, transitional gives each page a normal and an AMP version, and reader uses a separate simplified template. The mode changes what your branching code affects.

### How do I use a different sidebar on AMP pages?

Register a second sidebar with register_sidebar(), then in sidebar.php pick its ID with a ternary on your guarded helper and print it only if is_active_sidebar() is true. Block themes have no sidebar.php, so use template parts instead.

### How do I swap one template part for AMP?

Use the second argument of get_template_part(), for example mysite_is_amp() ? 'amp' : 'default'. WordPress falls back to the base file if a named one is missing.

### How do I test AMP branching?

Open a normal page and its AMP version (?amp=1 or /amp/ in transitional or reader mode). Check the markup, the validity status under AMP, Validated URLs, that the normal page is untouched, and that the site works with the plugin deactivated.

### Can I add JavaScript to AMP pages?

Custom JavaScript is generally not allowed in AMP pages. Skip enqueueing your script when the request is AMP to keep the page valid.
