This page short URL: rdd

wbAMP exposes a few methods so that other extensions can possibly alter the way they render their content when on an AMP page.


The API can be used only after the Joomla onAfterRoute event has taken place.

Reference

1.bool isAMPRequest()

Returns true if the current request is an AMP request.

2.string getCanonicalUrl()

If the current request is an AMP one, returns the fully qualified canonical URL of the corresponding regular HTML page.

3.string getAMPUrl($path = '', $full = true)

Gets the URL of the AMP version of a regular HTML page URL.

  • string $path
    if empty, the AMP URL for the current requested page is returned (whether an AMP page or a regular HTML page). Otherwise, the path, ie /path/to/my/regular-html-page (without domain name)

  • bool $full
    if true, a fully qualified URL is returned (ie: https://example.com/path/to/page.amp.html for instance), if false an URL relative to the site is returned (ie: /path/to/page.amp.html)

Usage

Those methods can be used through a static proxy class WbAMP:


echo 'AMP request: ' . (WbAMP::isAMPRequest() ? 'yes' : 'no');

echo '<br />Canonical: ' . WbAMP::getCanonicalUrl();

echo '<br />AMP: ' . WbAMP::getAMPUrl();