Skip to content

Instantly share code, notes, and snippets.

View johnregan3's full-sized avatar

John Regan johnregan3

View GitHub Profile
@johnregan3
johnregan3 / wp-amp-tutorial-amp-head.html
Created July 12, 2016 17:51
Example AMP template HTML <head>
<!doctype html>
<html >
<head>
<meta charset="utf-8">
<title>Sample document</title>
<link rel="canonical" href="./regular-html-version.html">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<scrip
@johnregan3
johnregan3 / wp-amp-tutorial-register-component-scripts.php
Last active July 13, 2016 00:57
Registering Component Scripts for AMP Extensions with the WP AMP plugin
<?php
/**
* Include AMP component scripts.
*
* Be sure to only register the scripts for the extensions
* that you really need to reduce page load times.
*
* @filter amp_post_template_data
*
* @param array $data Input from filter.
<?php
/**
* Add a custom AMP template file.
*
* Registers templates in a /templates subdirectory.
*
* @filter amp_post_template_file
*
* @param string $file The file name input.
* @param string $type The type of template.
@johnregan3
johnregan3 / wp-amp-tutorial-register-cpts.php
Last active July 21, 2016 17:54
Registering a Custom Post Type with the WP AMP plugin
<?php
/**
* Register CPTs to be included with AMP integration.
*
* Be sure to visit Settings > Permalinks and save twice
* to ensure the rewrite rules are flushed after adding this.
*
* @action amp_init
*/
function jr3_amp_register_post_types() {
@johnregan3
johnregan3 / wp-amp-tutorial-style.php
Last active July 21, 2016 19:28
Brief example of CSS for WP AMP style.php
<?php
/**
* Slightly modified version of the default WP AMP stylesheet, style.php.
*
* This is pared down for clarity.
*
* @link https://github.com/Automattic/amp-wp/blob/master/templates/style.php
*/
?>
/* Merriweather fonts */
<?php
define('DOMAIN_CURRENT_SITE', 'local-www.kiss925.com');
// ** Site URL settings ** //
define('WP_SITEURL', 'local-www.kiss925.com');
define('WP_HOME', 'local-www.kiss925.com');
@johnregan3
johnregan3 / wp-amp-tutorial-component-scripts.php
Last active September 28, 2016 16:03
Add component scripts to WP AMP
<?php
/**
* Register the amp-sidebar and amp-accordion component scripts with WP AMP.
*
* This goes in your amp.php
*/
function jr3_amp_component_scripts( $data ) {
$data['amp_component_scripts']['amp-sidebar'] = 'https://cdn.ampproject.org/v0/amp-sidebar-0.1.js';
$data['amp_component_scripts']['amp-accordion'] = 'https://cdn.ampproject.org/v0/amp-accordion-0.1.js';
@johnregan3
johnregan3 / amp-check-for-plugin.php
Last active September 28, 2016 16:04
Admin notice if the WP AMP Plugin is not installed.
<?php
/**
* Show an Admin Notice if the AMP plugin is not found.
*
* This is a basic implementation. Naturally, you'll want
* to add ajax support so that once this is dismissed, it goes
* away permanently. Also, you may want to limit the admin
* pages this displays to prevent annoying your users.
*
* @return bool
<?php
/**
* Add custom AMP template files.
*
* Registers templates in a /templates subdirectory.
*
* @filter amp_post_template_file
*
* @param string $file The file name input.
* @param string $type The type of template.
@johnregan3
johnregan3 / wp-amp-tutorial-social-share.php
Last active September 28, 2016 16:21
Example AMP Social Share buttons in WordPress
<?php
/*
* Example of using amp-social-share within WP.
*
* Note that Facebook requires an App ID {YOUR_FB_APP_ID}.
*
* Be sure to include the amp-social-share component script.
*/
<div class="share-buttons">
<amp-social-share type="facebook" width="32" height="32"