Skip to content

Instantly share code, notes, and snippets.

@hirejordansmith
Last active December 6, 2016 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirejordansmith/784ab445dc3e3207a92cdd804594ea17 to your computer and use it in GitHub Desktop.
Save hirejordansmith/784ab445dc3e3207a92cdd804594ea17 to your computer and use it in GitHub Desktop.
NDR AMP Code
body { font-family: Arial, sans-serif; }
.amp-wp-header { background: none; overflow: hidden; }
.amp-wp-header div { overflow: hidden; padding-bottom: 0; }
.amp-wp-title, h2, h3, h4 { font-weight: 400; }
.amp-wp-header a.amp-logo {
background: url(https://302mzo3s6lif441niv3xmjco-wpengine.netdna-ssl.com/wp-content/themes/nationaldebtrelief/images/logo-280.png) no-repeat;
margin: 0;
padding: 0;
width: 150px;
height: 45px;
display: block;
text-indent: -9999em;
background-size: 100%;
float: left;
}
.amp-wp-header a.phone {
color: #18027a;
float: right;
font-size: 18px;
padding-top: 10px;
}
.post-cta { background: #006896; text-align: center;
padding: 20px; }
.post-cta h2 { color: #fff; margin: 0 0 20px;}
.post-cta .button-wrap { margin: 0; }
.post-cta .button {
background: #1f00a9;
padding: 11px 35px;
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-size: 18px;
border-radius: 5px;
display: inline-block;
letter-spacing: 1px;
}
.amp-wp-header div {
padding: 10px 15px 2px;
}
.amp-wp-footer p { margin: 0 0 5px; }
amp-sidebar[side][open] {
background: #18027a;
}
amp-sidebar[side][open] { margin: 0; padding-top: 15px; }
amp-sidebar[side][open] li { list-style: none;}
amp-sidebar[side][open] li a { display: block; padding: 2px 35px 2px 25px; color: #fff; }
amp-sidebar[side][open] li a:hover {
background: #E2E6EF;
color: #333;
}
.menu-bar {
background: #18027a;
color: #fff;
padding: 20px;
}
<?php
add_action('amp_post_template_head','hjs_add_amp_sidebar_script');
function hjs_add_amp_sidebar_script() { ?>
<script async custom-element="amp-sidebar" src="https://cdn.ampproject.org/v0/amp-sidebar-0.1.js"></script>
<script async custom-element="amp-fit-text" src="https://cdn.ampproject.org/v0/amp-fit-text-0.1.js"></script>
<?php }
add_filter('the_content', 'inject_ad_text_after_n_chars');
function inject_ad_text_after_n_chars($content) {
if (is_amp_endpoint()) {
// only do this if post is longer than 1000 characters
$enable_length = 1500;
// insert after the first </p> after 500 characters
$after_character = 1000;
if (is_single() && strlen($content) > $enable_length) {
$before_content = substr($content, 0, $after_character);
$after_content = substr($content, $after_character);
$after_content = explode('</p>', $after_content);
$text = '
<div class="post-cta">
<h2>Do you qualify for debt consolidation?</h2>
<p class="button-wrap">
<a class="button" href=' . site_url('apply') . '/?ampid=' . get_the_ID() . '>Check Now!</a>
</p>
</div>
';
array_splice($after_content, 1, 0, $text);
$after_content = implode('</p>', $after_content);
return $before_content . $after_content;
}
}
else {
return $content;
}
}
<header id="#top" class="amp-wp-header">
<div class="menu-bar">
<a id="hamburger" class="button" on="tap:sidebar.open">
<amp-img srcset="https://www.nationaldebtrelief.com/wp-content/themes/nationaldebtrelief/images/mobile-menu-icon.png" width="24" height="24" alt="navigation" class="-amp-element -amp-layout-fixed -amp-layout-size-defined -amp-layout" style="width: 24px; height: 24px;"><img alt="navigation" class="-amp-fill-content -amp-replaced-content" src="https://www.nationaldebtrelief.com/wp-content/themes/nationaldebtrelief/images/mobile-menu-icon.png"></amp-img>
</a>
<amp-sidebar id="sidebar"
layout="nodisplay"
side="left">
<ul>
<li><a href="/">Home</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Options</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Contact Us</a></li>
<li><a href="#">Client Login</a></li>
<li><a href="#">Careers</a></li>
</ul>
</amp-sidebar>
</div>
<div>
<a class="amp-logo" href="<?php echo esc_url( $this->get( 'home_url' ) ); ?>">
<?php $site_icon_url = $this->get( 'site_icon_url' );
if ( $site_icon_url ) : ?>
<amp-img src="<?php echo esc_url( $site_icon_url ); ?>" width="32" height="32" class="amp-wp-site-icon"></amp-img>
<?php endif; ?>
<?php echo esc_html( $this->get( 'blog_name' ) ); ?>
</a>
<a class="phone" href="tel:8003009550">800-300-9550</a>
</div>
</header>
<!doctype html>
<html amp <?php echo AMP_HTML_Utils::build_attributes_string( $this->get( 'html_tag_attributes' ) ); ?>>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
<?php do_action( 'amp_post_template_head', $this ); ?>
<style amp-custom>
<?php $this->load_parts( array( 'style' ) ); ?>
<?php do_action( 'amp_post_template_css', $this ); ?>
</style>
</head>
<body class="<?php echo esc_attr( $this->get( 'body_class' ) ); ?>">
<?php $this->load_parts( array( 'header-bar' ) ); ?>
<article class="amp-wp-article">
<header class="amp-wp-article-header">
<h1 class="amp-wp-title"><?php echo wp_kses_data( $this->get( 'post_title' ) ); ?></h1>
<?php $this->load_parts( apply_filters( 'amp_post_article_header_meta', array( 'meta-author', 'meta-time' ) ) ); ?>
</header>
<?php $this->load_parts( array( 'featured-image' ) ); ?>
<div class="amp-wp-article-content">
<?php echo $this->get( 'post_amp_content' ); // amphtml content; no kses ?>
<div class="post-cta">
<h2>Do you qualify for debt consolidation?</h2>
<p class="button-wrap"><a class="button" href="<?php echo site_url('apply'); ?>/?ampid=<?php echo get_the_ID(); ?>">Check Now!</a></p>
</div>
</div>
<footer class="amp-wp-article-footer">
<?php $this->load_parts( apply_filters( 'amp_post_article_footer_meta', array( 'meta-taxonomy', 'meta-comments-link' ) ) ); ?>
</footer>
</article>
<?php $this->load_parts( array( 'footer' ) ); ?>
<?php do_action( 'amp_post_template_footer', $this ); ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment