Skip to content

Instantly share code, notes, and snippets.

View MohammedKaludi's full-sized avatar

Mohammed Kaludi MohammedKaludi

View GitHub Profile
@MohammedKaludi
MohammedKaludi / gist:40344ed8f1a7eba04f0df44a7bfe76e5
Last active August 7, 2018 15:50
Custom Module for AMP Page builder
<?php
add_filter('ampforwp_pagebuilder_modules_filter', 'new_pb_module', 99);
function new_pb_module( $data ){
$data['custom_text_module'] = custom_module_data();
return $data;
}
function custom_module_data(){
@MohammedKaludi
MohammedKaludi / custom-header.php
Last active May 30, 2017 11:07
AMPforWP Custom Header file code
<?php
// Remove Old File
add_action('init','ampforwp_remove_old_header_file',11);
function ampforwp_remove_old_header_file(){
remove_filter( 'amp_post_template_file', 'ampforwp_custom_header', 10, 3 );
}
// Register New Files
add_action('init','ampforwp_custom_header_files_register', 10);
function ampforwp_custom_header_files_register(){
add_filter( 'amp_post_template_file', 'ampforwp_custom_header_file', 10, 2 );
@MohammedKaludi
MohammedKaludi / gist:80aef3069b66e1d28ba1daee778afb1c
Created April 27, 2017 07:54
Custom Controls for AMP For WP plugin
<?php
if ( ! function_exists( 'ampforwp_create_custom_controls' ) ) {
function ampforwp_create_custom_controls() {
$controls[] = array(
'id' =>'ampforwp-example-select',
'type' => 'switch',
'title' => __('Example Select', 'redux-framework-demo'),
'default' => 0,
'true' => 'Enabled',
'false' => 'Disabled',
@MohammedKaludi
MohammedKaludi / gist:b68802673205db64551b4c31e0e4686f
Created April 1, 2017 11:39
Wrong SEO title and Wrong Structured Data when Custom AMP front page is on
// 12. Add Logo URL in the structured metadata
add_filter( 'amp_post_template_metadata', 'ampforwp_update_metadata', 10, 2 );
function ampforwp_update_metadata( $metadata, $post ) {
global $redux_builder_amp;
if (! empty( $redux_builder_amp['opt-media']['url'] ) ) {
$structured_data_main_logo = $redux_builder_amp['opt-media']['url'];
}
if (! empty( $redux_builder_amp['amp-structured-data-logo']['url'] ) ) {
@MohammedKaludi
MohammedKaludi / custom-css.php
Created January 21, 2017 13:03
Completely remove default CSS from AMPforWP plugin
add_action('pre_amp_render_post','ampforwp_remove_default_stylesheet',20);
function ampforwp_remove_default_stylesheet(){
remove_action('amp_post_template_css', 'ampforwp_additional_style_input');
}
@MohammedKaludi
MohammedKaludi / custom-css.php
Last active May 27, 2018 18:47
Add Custom CSS in AMPforWP via Hook
add_action('amp_post_template_css','ampforwp_add_custom_css_example', 11);
function ampforwp_add_custom_css_example() { ?>
/* Add your custom css here */
body {
background: red;
}
<?php
}
@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>
<?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: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);
}