Skip to content

Instantly share code, notes, and snippets.

View MohammedKaludi's full-sized avatar

Mohammed Kaludi MohammedKaludi

View GitHub Profile
@MohammedKaludi
MohammedKaludi / gist:31e577ecf37b327bf5048191793234b1
Created December 23, 2016 11:58
Custom banner extension: plugin header
<?php
/*
Plugin Name: AMP Custom Banner Extension
Plugin URI: https://wordpress.org/plugins/accelerated-mobile-pages/
Description: Extension made for AMP for WP to add a custom banner after the post content.
Version: 1.0
Author: Mohammed Kaludi
Author URI: http://ampforwp.com/
License: GPL2
*/
@MohammedKaludi
MohammedKaludi / gist:a951d09b883ca543261b439d0c232eff
Last active December 23, 2016 12:37
Custom banner extension : Custom banner code
add_action('ampforwp_after_post_content','amp_custom_banner_extension_insert_banner');
function amp_custom_banner_extension_insert_banner() { ?>
<div class="amp-custom-banner-after-post">
<a href="https://ampforwp.com/extensions">
<amp-img
src="https://ampforwp.com/wp-content/uploads/2016/12/amp-custom-banner.png"
width="728"
height="90"
alt="AMP Extension page">
</amp-img>
@MohammedKaludi
MohammedKaludi / gist:886da4067a9e71b80379d29eee5421e2
Last active December 23, 2016 14:40
AMP Custom Banner Extension : before styling
<?php
/*
Plugin Name: AMP Custom Banner Extension
Plugin URI: https://wordpress.org/plugins/accelerated-mobile-pages/
Description: Extension made for AMP for WP to add a custom banner after the post content.
Version: 1.0
Author: Mohammed Kaludi
Author URI: http://ampforwp.com/
License: GPL2
*/
@MohammedKaludi
MohammedKaludi / gist:583f78d43251ad9dbb4e3e83de8ec50c
Created December 23, 2016 14:15
AMP Custom Banner Extension : Styling
add_action('amp_post_template_css', 'amp_custom_banner_extension_styling');
function amp_custom_banner_extension_styling() { ?>
.amp-custom-banner-after-post {
text-align: center
}
<?php }
@MohammedKaludi
MohammedKaludi / gist:435536072d98412f64f9a8023b2795d8
Created December 23, 2016 14:41
AMP Custom Banner: Complete Extension
<?php
/*
Plugin Name: AMP Custom Banner Extension
Plugin URI: https://wordpress.org/plugins/accelerated-mobile-pages/
Description: Extension made for AMP for WP to add a custom banner after the post content.
Version: 1.0
Author: Mohammed Kaludi
Author URI: http://ampforwp.com/
License: GPL2
*/
function ampforwp_clicky_analytics() { ?>
<amp-analytics type="clicky">
<script type="application/json">
{
"vars": {
"site_id": "YOUR_SITE_ID_HERE"
}
}
</script>
</amp-analytics>
@MohammedKaludi
MohammedKaludi / gist:3840ab3cf52851148c01c28b73e56c1d
Last active January 3, 2017 12:50
Remove existing AMP analytics
add_action('init','ampforwp_remove_existing_analytics');
function ampforwp_remove_existing_analytics() {
remove_action('amp_post_template_footer','ampforwp_analytics',11);
}
@MohammedKaludi
MohammedKaludi / gist:0c44e1f7117719ab040ed813c0e3a4ff
Created January 3, 2017 12:49
Hook Clicky analytics into AMP
add_action('init','ampforwp_add_clicky_analytics_hook');
function ampforwp_add_clicky_analytics_hook() {
add_action('amp_post_template_footer','ampforwp_clicky_analytics',11);
}
<?php
// Remove all the existing analytics code
add_action('init','ampforwp_remove_existing_analytics');
function ampforwp_remove_existing_analytics() {
remove_action('amp_post_template_footer','ampforwp_analytics',11);
}
// Build the markup for Clicky Analytics code
function ampforwp_clicky_analytics() { ?>
<amp-analytics type="clicky">
@MohammedKaludi
MohammedKaludi / gist:6bceaa43fe61aeaa038c2a0527d755a9
Created January 18, 2017 16:43
Search form support for AMP
// Search Form
function ampforwp_get_search_form() {
$form = '<form role="search" method="get" id="searchform" class="searchform" target="_top" action="' . trailingslashit( get_bloginfo('url') ) . '?' . AMP_QUERY_VAR . '">
<div>
<label class="screen-reader-text" for="s">' . _x( 'AMP SEARCH:', 'label' ) . '</label>
<input type="text" value="' . get_search_query() . '" name="s" id="s" />
<input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
</div>