-
Notifications
You must be signed in to change notification settings - Fork 385
Adding Theme Support
Starting in version 0.7, your theme can register support for 'amp'
in order to support "Native AMP" or "Paired Mode."
Your entire site will use AMP (demo screencast, example site).
There will only be one version of each URL: the AMP version. There won't be URLs with /amp
or ?amp
appended.
In a theme you've developed or a child theme, add this in functions.php
. It should be in a callback for the action after_setup_theme:
add_theme_support( 'amp', array(
'comments_live_list' => true // example value
) );
Parameter | Type | Default | Description |
---|---|---|---|
comments_live_list |
boolean | false | Optional. Whether to use amp-live-list for comments. On making a comment, this will display the comment without a page refresh. If this parameter isn't present or is false, the page will refresh on making a comment. This also requires adding markup to your theme, please see this wiki page. |
There will be AMP and non-AMP versions of certain URLs, and this will use your custom templates for the AMP versions. Similar to the example above, place this in a callback:
add_theme_support( 'amp', array(
'template_dir' => 'amp-templates', // example value
'available_callback' => 'is_singular', // example
'comments_live_list' => true // example
) );
Parameter | Type | Description |
---|---|---|
template_dir |
string | Required. The path to the custom AMP "Paired Mode" template(s), relative to your theme. In the example above, you would add an amp-templates/ directory to the root of your theme, and place template(s) in it, like single.php . |
available_callback |
callable | Recommended. This callback should return a boolean that indicates whether to use "Paired Mode." In the example above, only if the request is_singular() will this look for an AMP template in the template_dir . If this callback returns false , there will be no AMP version of the URL, and it won't look for templates in template_dir . If this available_callback parameter isn't present, it will still look in the template_dir for the AMP templates. |
comments_live_list |
boolean | Optional. See description above. |
For any templates in your template_dir
, you can require
your standard template instead of creating a new one. For example, your amp-templates/single.php
file might simply have:
<?php require get_template_directory() . '/single.php';
You might also use is_amp_endpoint()
in that template to output different content for the AMP and non-AMP versions.
This will use your theme's stylesheet. But if it goes over the 50 KB CSS limit, the plugin won't add it.
- Weston Ruter's support post on "Paired Mode"
- Example Native AMP theme
Notice: Please also see the plugin documentation on amp-wp.org