# AMP for WordPress ## Overview This plugin adds support for the [Accelerated Mobile Pages](https://www.ampproject.org) (AMP) Project, which is an open source initiative that aims to provide mobile optimized content that can load instantly everywhere. With the plugin active, all posts on your site will have dynamically generated AMP-compatible versions, accessible by appending `/amp/` to the end your post URLs. For example, if your post URL is `http://example.com/2016/01/01/amp-on/`, you can access the AMP version at `http://example.com/2016/01/01/amp-on/amp/`. If you do not have [pretty permalinks](https://codex.wordpress.org/Using_Permalinks#mod_rewrite:_.22Pretty_Permalinks.22) enabled, you can do the same thing by appending `?amp=1`, i.e. `http://example.com/?p=123&=1` Note #1: that Pages and archives are not currently supported. Note #2: this plugin only creates AMP content but does not automatically display it to your users when they visit from a mobile device. That is handled by AMP consumers such as Google Search. For more details, see the [AMP Project FAQ](https://www.ampproject.org/docs/support/faqs.html). ## Customization / Templating The plugin ships with a default template that looks nice and clean and we tried to find a good balance between ease and extensibility when it comes to customization. You can tweak small pieces of the template or the entire thing depending on your needs. ### Where Do I Put My Code? The code snippets below and any other code-level customizations should happen in one of the following locations. If you're using an off-the-shelf theme (like from the WordPress.org Theme Directory): - A [child theme](https://developer.wordpress.org/themes/advanced-topics/child-themes/). - A custom plugin that you activate via the Dashboard. - A [mu-plugin](https://codex.wordpress.org/Must_Use_Plugins). If you're using a custom theme: - `functions.php` (or via a 'require' call to files that load from `functions.php`). - Any of the options above. ### Theme Mods The default template will attempt to draw from various theme mods, such as site icon, if supported by the active theme. #### Site Icon If you add a site icon, we will automatically replace the WordPress logo in the template. If you'd prefer to do it via code: ```php add_filter( 'amp_post_template_data', 'xyz_amp_set_site_icon_url' ); function xyz_amp_set_site_icon_url( $data ) { // Ideally a 32x32 image $data[ 'site_icon_url' ] = get_stylesheet_directory_uri() . '/images/amp-site-icon.png'; return $data; } ``` #### Logo Only If you want to hide the site text and just show a logo, use the `amp_post_template_css` action. The following colors the title bar black, hides the site title, and replaces it with a centered logo: ```php add_action( 'amp_post_template_css', 'xyz_amp_additional_css_styles' ); function xyz_amp_additional_css_styles( $amp_template ) { // only CSS here please... ?> nav.amp-wp-title-bar { padding: 12px 0; background: #000; } nav.amp-wp-title-bar a { background-image: url( 'https://example.com/path/to/logo.png' ); background-repeat: no-repeat; background-size: contain; display: block; height: 28px; width: 94px; margin: 0 auto; text-indent: -9999px; } 'ImageObject', 'url' => get_template_directory_uri() . '/images/my-amp-metadata-logo.png', 'height' => 60, 'width' => 600, ); return $metadata; } ``` #### Template Meta (Author, Date, etc.) For the meta section of the template (i.e. author, date, taxonomies, etc.), you can override templates for the existing sections, remove them, add new ones. ##### Example: Override Author Template from Theme Create a folder in your theme called `amp` and add a file called `meta-author.php` with the following: ```php