request ); $amp_url = trailingslashit($current_archive_url).'?amp'; } else { $amp_url = amp_get_permalink( get_queried_object_id() ); } global $post; $ampforwp_amp_post_on_off_meta = get_post_meta( $post->ID ); if( $ampforwp_amp_post_on_off_meta['ampforwp-amp-on-off'][0] === 'hide-amp' ) { //dont Echo anything } else { printf( '', esc_url( $amp_url ) ); } } //end of ampforwp_home_archive_rel_canonical() // Remove default wordpress rel canonical add_filter('amp_frontend_show_canonical','ampforwp_remove_default_canonical'); if (! function_exists('ampforwp_remove_default_canonical') ) { function ampforwp_remove_default_canonical() { return false; } } // 2. Custom Design // Add Homepage AMP file code add_filter( 'amp_post_template_file', 'ampforwp_custom_template', 10, 3 ); function ampforwp_custom_template( $file, $type, $post ) { // Custom Homepage and Archive file global $redux_builder_amp; if($redux_builder_amp['amp-frontpage-select-option'] == 0) { if ( is_home() || is_archive() ) { if ( 'single' === $type ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/index.php'; } } } elseif ($redux_builder_amp['amp-frontpage-select-option'] == 1) { if ( is_home() ) { if ( 'single' === $type ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/frontpage.php'; } } if ( is_archive() ) { if ( 'single' === $type ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/index.php'; } } } // Custom Single file if ( is_single() || is_page() ) { if('single' === $type && !('product' === $post->post_type )) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/single.php'; } } return $file; } // 3. Custom Style files add_filter( 'amp_post_template_file', 'ampforwp_set_custom_style', 10, 3 ); function ampforwp_set_custom_style( $file, $type, $post ) { if ( 'style' === $type ) { $file = ''; } return $file; } // 4. Custom Header files add_filter( 'amp_post_template_file', 'ampforwp_custom_header', 10, 3 ); function ampforwp_custom_header( $file, $type, $post ) { if ( 'header-bar' === $type ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/header-bar.php'; } return $file; } // 4.1 Custom Meta-Author files add_filter( 'amp_post_template_file', 'ampforwp_set_custom_meta_author', 10, 3 ); function ampforwp_set_custom_meta_author( $file, $type, $post ) { if ( 'meta-author' === $type ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/meta-author.php'; } return $file; } // 4.2 Custom Meta-Taxonomy files add_filter( 'amp_post_template_file', 'ampforwp_set_custom_meta_taxonomy', 10, 3 ); function ampforwp_set_custom_meta_taxonomy( $file, $type, $post ) { if ( 'meta-taxonomy' === $type ) { $file = AMPFORWP_PLUGIN_DIR . '/templates/meta-taxonomy.php'; } return $file; } // 4.5 Added hook to add more layout. do_action('ampforwp_after_features_include'); // 5. Customize with Width of the site add_filter( 'amp_content_max_width', 'ampforwp_change_content_width' ); function ampforwp_change_content_width( $content_max_width ) { return 1000; } // 6. Add required Javascripts for extra AMP features add_action('amp_post_template_head','ampforwp_register_additional_scripts', 20); function ampforwp_register_additional_scripts() { global $redux_builder_amp; if ( class_exists('WPSEO_Options') && class_exists('YoastSEO_AMP') ) { $yoast_glue_seo = get_option('wpseo_amp'); } if ( empty( $yoast_glue_seo['analytics-extra'] ) ) { ?>

'; $output .= ''; $output .= ''; $output .= ' '; echo $output; } } // Above Footer Global add_action('amp_post_template_footer','ampforwp_footer_advert',8); function ampforwp_footer_advert() { global $redux_builder_amp; if($redux_builder_amp['enable-amp-ads-2'] == true) { if($redux_builder_amp['enable-amp-ads-select-2'] == 1) { $advert_width = '300'; $advert_height = '250'; } elseif ($redux_builder_amp['enable-amp-ads-select-2'] == 2) { $advert_width = '336'; $advert_height = '280'; } elseif ($redux_builder_amp['enable-amp-ads-select-2'] == 3) { $advert_width = '728'; $advert_height = '90'; } elseif ($redux_builder_amp['enable-amp-ads-select-2'] == 4) { $advert_width = '300'; $advert_height = '600'; } elseif ($redux_builder_amp['enable-amp-ads-select-2'] == 5) { $advert_width = '320'; $advert_height = '100'; } elseif ($redux_builder_amp['enable-amp-ads-select-2'] == 6) { $advert_width = '200'; $advert_height = '50'; } elseif ($redux_builder_amp['enable-amp-ads-select-2'] == 7) { $advert_width = '320'; $advert_height = '50'; } $output = '
'; $output .= ''; $output .= ''; $output .= '
'; echo $output; } } // Below Title Single add_action('ampforwp_before_post_content','ampforwp_before_post_content_advert'); add_action('ampforwp_inside_post_content_before','ampforwp_before_post_content_advert'); function ampforwp_before_post_content_advert() { global $redux_builder_amp; if($redux_builder_amp['enable-amp-ads-3'] == true) { if($redux_builder_amp['enable-amp-ads-select-3'] == 1) { $advert_width = '300'; $advert_height = '250'; } elseif ($redux_builder_amp['enable-amp-ads-select-3'] == 2) { $advert_width = '336'; $advert_height = '280'; } elseif ($redux_builder_amp['enable-amp-ads-select-3'] == 3) { $advert_width = '728'; $advert_height = '90'; } elseif ($redux_builder_amp['enable-amp-ads-select-3'] == 4) { $advert_width = '300'; $advert_height = '600'; } elseif ($redux_builder_amp['enable-amp-ads-select-3'] == 5) { $advert_width = '320'; $advert_height = '100'; } elseif ($redux_builder_amp['enable-amp-ads-select-3'] == 6) { $advert_width = '200'; $advert_height = '50'; } elseif ($redux_builder_amp['enable-amp-ads-select-3'] == 7) { $advert_width = '320'; $advert_height = '50'; } $output = '
'; $output .= ''; $output .= ''; $output .= '
'; echo $output; } } // Below Content Single add_action('ampforwp_after_post_content','ampforwp_after_post_content_advert'); add_action('ampforwp_inside_post_content_after','ampforwp_after_post_content_advert'); function ampforwp_after_post_content_advert() { global $redux_builder_amp; if($redux_builder_amp['enable-amp-ads-4'] == true) { if($redux_builder_amp['enable-amp-ads-select-4'] == 1) { $advert_width = '300'; $advert_height = '250'; } elseif ($redux_builder_amp['enable-amp-ads-select-4'] == 2) { $advert_width = '336'; $advert_height = '280'; } elseif ($redux_builder_amp['enable-amp-ads-select-4'] == 3) { $advert_width = '728'; $advert_height = '90'; } elseif ($redux_builder_amp['enable-amp-ads-select-4'] == 4) { $advert_width = '300'; $advert_height = '600'; } elseif ($redux_builder_amp['enable-amp-ads-select-4'] == 5) { $advert_width = '320'; $advert_height = '100'; } elseif ($redux_builder_amp['enable-amp-ads-select-4'] == 6) { $advert_width = '200'; $advert_height = '50'; } elseif ($redux_builder_amp['enable-amp-ads-select-4'] == 7) { $advert_width = '320'; $advert_height = '50'; } $output = '
'; $output .= ''; $output .= ''; $output .= '
'; echo $output; } } // 10. Analytics Area add_action('amp_post_template_footer','ampforwp_analytics',11); function ampforwp_analytics() { // 10.1 Analytics Support added for Google Analytics global $redux_builder_amp; if ( $redux_builder_amp['amp-analytics-select-option']=='1' ){ ?> ]*/', '', $content); $content = preg_replace('/vocab=[^>]*/', '', $content); $content = preg_replace('/type=[^>]*/', '', $content); $content = preg_replace('/value=[^>]*/', '', $content); $content = preg_replace('/date=[^>]*/', '', $content); $content = preg_replace('/noshade=[^>]*/', '', $content); $content = preg_replace('/contenteditable=[^>]*/', '', $content); $content = preg_replace('/time=[^>]*/', '', $content); $content = preg_replace('/non-refundable=[^>]*/', '', $content); $content = preg_replace('/security=[^>]*/', '', $content); $content = preg_replace('/deposit=[^>]*/', '', $content); $content = preg_replace('/for=[^>]*/', '', $content); $content = preg_replace('/nowrap="nowrap"/', '', $content); $content = preg_replace('#(.*?)#i', '', $content); $content = preg_replace('#(.*?)#i', '', $content); $content = preg_replace('#(.*?)#i', '', $content); $content = preg_replace('#(.*?)#i', '', $content); $content = preg_replace('##i', '', $content); $content = preg_replace('##i', '', $content); /* Removed So Inline style can work $content = preg_replace('##i', '', $content); */ $content = preg_replace('/href="javascript:void*/', ' ', $content); $content = preg_replace('/]*>.*?<\/script>/i', '', $content); //for removing attributes within html tags $content = preg_replace('/(<[^>]+) onclick=".*?"/', '$1', $content); /* Removed So Inline style can work $content = preg_replace('/(<[^>]+) style=".*?"/', '$1', $content); */ $content = preg_replace('/(<[^>]+) rel=".*?"/', '$1', $content); $content = preg_replace('/(<[^>]+) ref=".*?"/', '$1', $content); $content = preg_replace('/(<[^>]+) date/', '$1', $content); $content = preg_replace('/(<[^>]+) spellcheck/', '$1', $content); //removing scripts and rel="nofollow" from Body and from divs //issue #268 $content = str_replace(' rel="nofollow"',"",$content); $content = preg_replace('/]*>.*?<\/script>/i', '', $content); /// simpy add more elements to simply strip tag but not the content as so /// Array ("p","font"); $tags_to_strip = Array("thrive_headline" ); foreach ($tags_to_strip as $tag) { $content = preg_replace("/<\\/?" . $tag . "(.|\\s)*?>/",'',$content); } // $content = preg_replace('/ 'ImageObject', 'url' => $structured_data_logo , 'height' => 36, 'width' => 190, ); //code for adding 'description' meta from Yoast SEO if($redux_builder_amp['ampforwp-seo-yoast-custom-description']){ if ( class_exists('WPSEO_Frontend') ) { $front = WPSEO_Frontend::get_instance(); $desc = $front->metadesc( false ); if ( $desc ) { $metadata['description'] = $desc; } } } //End of code for adding 'description' meta from Yoast SEO return $metadata; } // 13. Add Custom Placeholder Image for Structured Data. // if there is no image in the post, then use this image to validate Structured Data. add_filter( 'amp_post_template_metadata', 'ampforwp_update_metadata_featured_image', 10, 2 ); function ampforwp_update_metadata_featured_image( $metadata, $post ) { global $redux_builder_amp; $post_id = $post->ID; $post_image_id = get_post_thumbnail_id( $post_id ); $structured_data_image = wp_get_attachment_image_src( $post_image_id, 'full' ); $post_image_check = $structured_data_image; if ( $post_image_check == false) { $structured_data_image = $redux_builder_amp['amp-structured-data-placeholder-image']['url']; $structured_data_height = intval($redux_builder_amp['amp-structured-data-placeholder-image-height']); $structured_data_width = intval($redux_builder_amp['amp-structured-data-placeholder-image-width']); $metadata['image'] = array( '@type' => 'ImageObject', 'url' => $structured_data_image , 'height' => $structured_data_height, 'width' => $structured_data_width, ); } // Custom Structured Data information for Archive, Categories and tag pages. if ( is_archive() ) { $structured_data_image = $redux_builder_amp['amp-structured-data-placeholder-image']['url']; $structured_data_height = intval($redux_builder_amp['amp-structured-data-placeholder-image-height']); $structured_data_width = intval($redux_builder_amp['amp-structured-data-placeholder-image-width']); $structured_data_archive_title = "Archived Posts"; $structured_data_author = get_userdata( 1 ); if ( $structured_data_author ) { $structured_data_author = $structured_data_author->display_name ; } else { $structured_data_author = "admin"; } $metadata['image'] = array( '@type' => 'ImageObject', 'url' => $structured_data_image , 'height' => $structured_data_height, 'width' => $structured_data_width, ); $metadata['author'] = array( '@type' => 'Person', 'name' => $structured_data_author , ); $metadata['headline'] = $structured_data_archive_title; } return $metadata; } // 14. Adds a meta box to the post editing screen for AMP on-off on specific pages. /** * Adds a meta box to the post editing screen for AMP on-off on specific pages */ function ampforwp_title_custom_meta() { add_meta_box( 'ampforwp_title_meta', __( 'Show AMP for Current Page?' ), 'ampforwp_title_callback', 'post','side' ); add_meta_box( 'ampforwp_title_meta', __( 'Show AMP for Current Page?' ), 'ampforwp_title_callback', 'page','side' ); } add_action( 'add_meta_boxes', 'ampforwp_title_custom_meta' ); /** * Outputs the content of the meta box for AMP on-off on specific pages */ function ampforwp_title_callback( $post ) { wp_nonce_field( basename( __FILE__ ), 'ampforwp_title_nonce' ); $ampforwp_stored_meta = get_post_meta( $post->ID ); ?>

ID, 'ampforwp-amp-on-off', true); if ( $ampforwp_amp_status == 'hide-amp' ) { $input = false; } return $input; } // 15. Disable New Relic's extra script that its adds in AMP pages. add_action( 'amp_post_template_data', 'ampforwp_disable_new_relic_scripts' ); if ( ! function_exists('ampforwp_disable_new_relic_scripts') ) { function ampforwp_disable_new_relic_scripts( $data ) { if ( ! function_exists( 'newrelic_disable_autorum' ) ) { return $data; } if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) { newrelic_disable_autorum(); } return $data; } } // 16. Remove Unwanted Scripts if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) { add_action( 'wp_enqueue_scripts', 'ampforwp_remove_unwanted_scripts',20 ); } function ampforwp_remove_unwanted_scripts() { wp_dequeue_script('jquery'); } // Remove Print Scripts and styles function ampforwp_remove_print_scripts() { if ( is_amp_endpoint() ) { function ampforwp_remove_all_scripts() { global $wp_scripts; $wp_scripts->queue = array(); } add_action('wp_print_scripts', 'ampforwp_remove_all_scripts', 100); function ampforwp_remove_all_styles() { global $wp_styles; $wp_styles->queue = array(); } add_action('wp_print_styles', 'ampforwp_remove_all_styles', 100); // Remove Print Emoji for Nextgen Gallery support remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'wp_print_styles', 'print_emoji_styles' ); } } add_action( 'template_redirect', 'ampforwp_remove_print_scripts' ); // 17. Archives Canonical in AMP version // function ampforwp_rel_canonical_archive() { // // // $archivelink = esc_url( get_permalink( $id ) . AMP_QUERY_VAR . '/' ); // echo "\n"; // } // add_action( 'amp_post_template_head', 'ampforwp_rel_canonical_archive' ); // 18. Custom Canonical for Homepage // function ampforwp_rel_canonical() { // if ( !is_home() ) // return; // // $link = esc_url( get_permalink( $id ) . AMP_QUERY_VAR . '/' ); // $homelink = get_home_url(); // echo "\n"; // } // add_action( 'amp_post_template_head', 'ampforwp_rel_canonical' ); // 18.5. Custom Canonical for Frontpage // function ampforwp_rel_canonical_frontpage() { // if ( is_home() || is_front_page() ) // return; // // $link = esc_url( get_permalink( $id ) . AMP_QUERY_VAR . '/' ); // $homelink = get_home_url(); // echo "\n"; // } // add_action( 'amp_post_template_head', 'ampforwp_rel_canonical_frontpage' ); // 19. Remove Canonical tags function ampforwp_amp_remove_actions() { if ( is_home() || is_front_page() || is_archive() ) { remove_action( 'amp_post_template_head', 'amp_post_template_add_canonical' ); } } add_action( 'amp_post_template_head', 'ampforwp_amp_remove_actions', 9 ); // 20. Remove the default Google font for performance // add_action( 'amp_post_template_head', function() { // remove_action( 'amp_post_template_head', 'amp_post_template_add_fonts' ); // }, 9 ); // 21. Remove Schema data from All In One Schema.org Rich Snippets Plugin add_action( 'pre_amp_render_post', 'ampforwp_remove_schema_data' ); function ampforwp_remove_schema_data() { remove_filter('the_content','display_rich_snippet'); } // 22. Removing author links from comments Issue #180 if( ! function_exists( "disable_comment_author_links" ) ) { function ampforwp_disable_comment_author_links( $author_link ){ $is_amp_endpoint = is_amp_endpoint(); if ( $is_amp_endpoint ) { return strip_tags( $author_link ); } else { return $author_link; } } add_filter( 'get_comment_author_link', 'ampforwp_disable_comment_author_links' ); } // 23. The analytics tag appears more than once in the document. This will soon be an error remove_action( 'amp_post_template_head', 'quads_amp_add_amp_ad_js'); // 24. Seperate Sticky Single Social Icons // TO DO: we can directly call social-icons.php instead of below code add_action('amp_post_template_footer','ampforwp_sticky_social_icons'); function ampforwp_sticky_social_icons(){ global $redux_builder_amp; if($redux_builder_amp['enable-single-social-icons'] == true && is_single() ) { ?> ' ); } else { echo strip_tags($redux_builder_amp['ampforwp-seo-custom-additional-meta'], '' ); } } add_action( 'amp_post_template_head', 'ampforwp_custom_yoast_meta' ); //26. Extending Title Tagand De-Hooking the Standard one from AMP add_action('amp_post_template_include_single','remove_this'); function remove_this(){ remove_action('amp_post_template_head','amp_post_template_add_title'); add_action('amp_post_template_head','ampforwp_custom_title_tag'); function ampforwp_custom_title_tag(){ ?> <?php global $redux_builder_amp; // title for a single post and single page if( is_single() || is_page() ){ global $post; $title = $post->post_title; echo $title . ' | ' . get_option( 'blogname' ) ; } $site_title = get_bloginfo('name') . ' | ' . get_option( 'blogdescription' ) ; if ( is_home() ) { if ( $redux_builder_amp['amp-frontpage-select-option']== 1) { $ID = $redux_builder_amp['amp-frontpage-select-option-pages']; $site_title = get_the_title( $ID ) . ' | ' . get_option('blogname'); } echo $site_title ; } ?> ID ); if( $ampforwp_amp_post_on_off_meta['ampforwp-amp-on-off'][0] === 'hide-amp' ) { $skip = true; } return $skip; }