: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
use AMPforWP\AMPVendor\AMP_Content;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
/* This file will contain all the Extra FEATURES.
0.9. AMP Design Manager Files
1. Add Home REL canonical
4.1 Custom Meta-Author files
4.2 Custom Meta-Taxonomy files
4.5 Added hook to add more layout.
5. Customize with Width of the site
6. Add required Javascripts for extra AMP features
6.1 Adding Analytics Scripts
8. Add Main tag as a Wrapper ( removed in 0.8.9 )
10.1 Analytics Support added for Google Analytics
10.2 Analytics Support added for segment.com
10.3 Analytics Support added for Piwik
10.4 Analytics Support added for quantcast
10.5 Analytics Support added for comscore
10.6 Analytics Support added for Effective Measure
10.7 Analytics Support added for StatCounter
10.8 Analytics Support added for Histats Analytics
10.9 Analytics Support added for Yandex Metrika
10.10 Analytics Support added for Chartbeat Analytics
10.11 Analytics Support added for Alexa Metrics
11. Strip unwanted codes and tags from the_content
12. Add Logo URL in the structured metadata
13. Add Custom Placeholder Image for Structured Data.
14. Adds a meta box to the post editing screen for AMP on-off on specific pages.
15. Disable New Relic's extra script that its adds in AMP pages.
16. Remove Unwanted Scripts
17. Archives Canonical in AMP version
18. Custom Canonical for Homepage
19. Remove Canonical tags
20. Remove the default Google font for performance ( removed in 0.8.9 )
21. Remove Schema data from All In One Schema.org Rich Snippets Plugin
22. Removing author links from comments Issue #180
23. The analytics tag appears more than once in the document. This will soon be an error
24. Seperate Sticky Single Social Icons
26. Extending Title Tagand De-Hooking the Standard one from AMP
27. Fixing the defer tag issue [Finally!]
28. Properly removes AMP if turned off from Post panel
29. Remove analytics code if Already added by Glue or Yoast SEO
30. TagDiv menu issue removed
31. removing scripts added by cleantalk
32. various lazy loading plugins Support
33. Google tag manager support added
34. social share boost compatibility Ticket #387
35. Disqus Comments Support
36. remove photon support in AMP
37. compatibility with wp-html-compression
38. #529 editable archives
39. #560 Header and Footer Editable html enabled script area
41. Rewrite URL only on save #511
42. registeing AMP sidebars
43. custom actions for widgets output
44. auto adding /amp for the menu
45. search,frontpage,homepage structured data
46. search search search everywhere #615
47. social js properly adding when required
48. Remove all unwanted scripts on search pages
49. Properly adding ad Script the AMP way
50. Properly adding noditification Scritps the AMP way
51. Adding Digg Digg compatibility with AMP
52. Adding a generalized sanitizer function for purifiying normal html to amp-html
53. Removed AMP-WooCommerce Code and added it in AMP-WooCommerce #929
54. Change the default values of post meta for AMP pages.
55. Call Now Button Feature added
56. Multi Translation Feature #540
57. Adding Updated date at in the Content
58. YouTube Shortcode compatablity with AMP #557
60. Remove Category Layout modification code added by TagDiv #842 and #796
62. Adding Meta viewport via hook instead of direct #878
63. Frontpage Comments #682
65. Remove Filters code added through Class by other plugins
66. Make AMP compatible with Squirrly SEO
69. Post Pagination #834 #857
70. Hide AMP by specific Categories #872
71. Alt tag for thumbnails #1013 and For Post ID in Body tag #1006
72. Blacklist Sanitizer Added back #1024
73. View AMP Site below View Site In Dashboard #1076
74. Featured Image check from Custom Fields
76. Body Class for AMP pages
78. Saved Custom Post Types for AMP in Options for Structured Data
80. Mobile Preview styling
81. Duplicate Featured Image Support
82. Grab Featured Image from The Content
83. Advance Analytics(Google Analytics)
85. Caption for Gallery Images
86. minify the content of pages
90. Set Header last modified information
91. Comment Author Gravatar URL
92. View AMP in Admin Bar
93. added AMP url purifire for amphtml
94. OneSignal Push Notifications
95. Modify menu link attributes for SiteNavigationElement Schema Markup #1229 #1345
96. ampforwp_is_front_page() ampforwp_is_home() and ampforwp_is_blog is created
97. Change the format of the post date on Loops #1384
98. Create Dynamic url of amp according to the permalink structure #1318
99. Merriweather Font Management
100. Flags compatibility in Menu
101. Function for Logo attributes
102. SD Feature Image Guidlines #2838
add_amp_theme_support('AMP-logo');
add_amp_theme_support('AMP-loop');
if(ampforwp_get_setting('amp-gdpr-compliance-switch')) {
add_amp_theme_support('AMP-gdpr');
add_amp_theme_support('AMP-menu');
// Adding AMP-related things to the main theme
global $redux_builder_amp;
// 0.9. AMP Design Manager Files
require AMPFORWP_PLUGIN_DIR .'templates/design-manager.php';
// Custom Frontpage items
require AMPFORWP_PLUGIN_DIR .'templates/frontpage-elements.php';
require AMPFORWP_PLUGIN_DIR . '/classes/class-ampforwp-youtube-embed.php' ;
require AMPFORWP_PLUGIN_DIR .'templates/ampforwp-custom-post-type.php';
// TODO: Update this function
function ampforwp_include_customizer_files(){
global $redux_builder_amp;
$amp_plugin_activation_check;
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
$amp_plugin_activation_check = is_plugin_active( 'amp/amp.php' );
if ( isset ($redux_builder_amp['amp-design-selector']) && 4 != $redux_builder_amp['amp-design-selector'] ) {
return require AMPFORWP_PLUGIN_DIR .'templates/customizer/customizer.php' ;
ampforwp_include_customizer_files();
define('AMPFORWP_COMMENTS_PER_PAGE', ampforwp_define_comments_number() );
// Define number of comments
function ampforwp_define_comments_number(){
global $redux_builder_amp;
$number_of_comments = '';
if(isset($redux_builder_amp['ampforwp-number-of-comments'])){
$number_of_comments = $redux_builder_amp['ampforwp-number-of-comments'];
return $number_of_comments;
// 1. Add Home REL canonical
// Add AMP rel-canonical for home and archive pages
add_action('amp_init','ampforwp_allow_homepage');
function ampforwp_allow_homepage() {
add_action( 'wp', 'ampforwp_add_endpoint_actions' );
function ampforwp_add_endpoint_actions() {
$ampforwp_is_amp_endpoint = ampforwp_is_amp_endpoint();
if ( $ampforwp_is_amp_endpoint ) {
AMPforWP\AMPVendor\amp_prepare_render();
add_action( 'wp_head', 'ampforwp_home_archive_rel_canonical', 1 );
$cpage_var = get_query_var('cpage');
remove_action( 'wp_head', 'ampforwp_home_archive_rel_canonical', 1 );
function ampforwp_amphtml_generator(){
global $redux_builder_amp;
$endpoint_check = ampforwp_get_setting('amp-core-end-point');
if(get_query_var('paged') && true == ampforwp_get_setting('amp-paginated-pages-indexing')) {
if( is_home() && is_front_page() && !ampforwp_get_setting('ampforwp-homepage-on-off-support') ) {
if( is_front_page() && ! ampforwp_get_setting('ampforwp-homepage-on-off-support') ) {
// HIDE/SHOW TAG AND CATEGORY #4326
if(is_tag() || is_category() || is_tax()){
$amp_queried_object = get_queried_object();
if (is_object($amp_queried_object) && property_exists($amp_queried_object, 'term_id'))
$term_id = $amp_queried_object->term_id;
$tax_status = ampforwp_get_taxonomy_meta($term_id,'status');
$tax_status = ampforwp_get_taxonomy_meta('','post_status');
// Skip this condition for woocommerce product archive and shop pages.
if( function_exists('amp_woocommerce_pro_add_woocommerce_support') && (function_exists('is_product_category') && !is_product_category()) && (function_exists('is_product_tag') && !is_product_tag()) && (function_exists('is_shop') && !is_shop() ) ){
if( is_archive() && ( !ampforwp_get_setting('ampforwp-archive-support') || ( is_category() && !ampforwp_get_setting('ampforwp-archive-support-cat') ) || ( is_tag() && !ampforwp_get_setting('ampforwp-archive-support-tag') ))){
// When amp woocommerce pro plugin is not active.
if ( is_archive() && !function_exists('amp_woocommerce_pro_add_woocommerce_support') ) {
if(!ampforwp_get_setting('ampforwp-archive-support')){
if( is_category() && !ampforwp_get_setting('ampforwp-archive-support-cat') ){
if( is_tag() && !ampforwp_get_setting('ampforwp-archive-support-tag') ){
// #1192 Password Protected posts exclusion
if(post_password_required( $post )){
// #1443 AMP should be skip on the check out page
if(class_exists( 'WooCommerce' )){
if(function_exists('is_checkout') && is_checkout()){
if(function_exists('is_account_page') && is_account_page()){
// Search results on/off option #3786
if(is_search() && 0 == ampforwp_get_setting('amp-redirection-search')){
if(function_exists('yith_wishlist_constructor')){
$class = get_body_class();
if(in_array("woocommerce-wishlist", $class)){
// #872 no-amphtml if selected as hide from settings
if ( is_category_amp_disabled() ) {
if ( is_page() && ! ampforwp_get_setting('amp-on-off-for-all-pages') && ! is_home() && ! is_front_page() ) {
if ( is_home() && ! ampforwp_is_blog() && !ampforwp_get_setting('ampforwp-homepage-on-off-support') ) {
$amp_auth_url = ampforwp_get_author_page_url();
return esc_url_raw($amp_auth_url);
if (!ampforwp_is_home() && !ampforwp_is_front_page() && !ampforwp_is_blog() && !is_category() && !is_tag() && !is_singular( array('page', 'attachment', 'post')) && !function_exists('amp_woocommerce_pro_add_woocommerce_support')){
if (empty(ampforwp_get_setting('ampforwp-custom-type'))) {
$page_for_posts = intval(get_option( 'page_for_posts' ));
$post_id = ampforwp_get_the_ID();
if ( ampforwp_is_blog() && ! ampforwp_get_setting('amp-on-off-for-all-pages') && ($page_for_posts != $post_id ) ) {
$query_arg_array = $wp->query_vars;
if( in_array( "cpage" , $query_arg_array ) ) {
if( is_front_page() && $wp->query_vars['cpage'] >= '2' ) {
if( is_singular() && $wp->query_vars['cpage'] >= '2' ) {
if ( is_home() || is_front_page() || is_archive() ){
$current_archive_url = home_url( $wp->request );
// If its custom permalink with /index.php/ #3279
if ( is_archive() && false !== strpos($wp->matched_rule, 'index.php') && false === strpos($current_archive_url, 'index.php') ) {
$current_archive_url = home_url( 'index.php/' . $wp->request );
$amp_url = trailingslashit($current_archive_url);
if ($endpoint_check && (is_tax() || is_post_type_archive())) {
$amp_url = ampforwp_url_controller($amp_url);
$amp_url = AMPforWP\AMPVendor\amp_get_permalink( get_queried_object_id() );
if ( ampforwp_is_blog() ) {
$post_id = ampforwp_get_blog_details('id');
$ampforwp_amp_post_on_off_meta = get_post_meta( $post_id,'ampforwp-amp-on-off',true);
if ( ( is_singular() || ampforwp_is_blog() ) && $ampforwp_amp_post_on_off_meta === 'hide-amp' ) {
$supported_types = ampforwp_get_all_post_types();
if(isset($supported_types['web-story'])){
$supported_types['web-story'] = '';
$supported_types = apply_filters('get_amp_supported_post_types',$supported_types);
if(is_home() || is_front_page()){
if( ampforwp_get_setting('ampforwp-homepage-on-off-support') == 1
&& ampforwp_get_setting('amp-on-off-for-all-posts') == 0
&& ampforwp_get_setting('amp-on-off-for-all-pages') == 0 ){
$supported_types['post'] = 'post';
$supported_amp_post_types = in_array( $type , $supported_types );
$query_arg_array = $wp->query_vars;
if( array_key_exists( 'paged' , $query_arg_array ) ) {
if ( (is_home() || is_archive()) && $wp->query_vars['paged'] >= '2' ) {
$new_url = home_url('/');
// If its custom permalink with /index.php/ #3537
if ( (is_home() || is_archive()) && false !== strpos($wp->matched_rule, 'index.php') && false === strpos( home_url( $wp->request ), 'index.php') ) {
$new_url = home_url( 'index.php' );
$new_url = str_replace($o_url, $new_url, $amp_url);
$new_url = user_trailingslashit($new_url);
$category_path = $wp->request;
if ( null != $category_path && true != $endpoint_check) {
$explode_path = explode("/",$category_path);
$inserted = array(AMPFORWP_AMP_QUERY_VAR);
array_splice( $explode_path, -2, 0, $inserted );
$impode_url = implode('/', $explode_path);
$amp_url = $new_url . $impode_url ;
if( is_search() && $wp->query_vars['paged'] >= '2' ) {
$current_search_url =trailingslashit(get_home_url()) . $wp->request .'/'."?amp=1&s=".get_search_query();
$amp_url = user_trailingslashit($amp_url);
$current_search_url =trailingslashit(get_home_url())."?amp=1&s=".get_search_query();
$amp_url = untrailingslashit($current_search_url);
if(!ampforwp_get_setting('amp-core-end-point') && !ampforwp_get_setting('ampforwp-amp-takeover')){
$amp_url = ampforwp_url_purifier($amp_url);
if(true == ampforwp_get_setting('amp-core-end-point') && (!is_home() && !is_front_page() && !is_archive())){
$amp_url = add_query_arg( 'amp', '', get_the_permalink() );
if( $supported_amp_post_types || ampforwp_is_front_page() ) {
if(true == ampforwp_get_setting('amp-core-end-point')){
if( class_exists('SitePress') ){
if( get_option('permalink_structure') ){
global $sitepress_settings, $wp;
$wpml_lang_checker = false;
if($sitepress_settings[ 'language_negotiation_type' ] == 3){
$amp_url = esc_url($amp_url);
$active_langs = $sitepress_settings['active_languages'];
foreach ($active_langs as $active_lang) {
if (preg_match('/\?lang='.$active_lang.'/', $amp_url)){
$amp_url = preg_replace('/&amp=1/', '', $amp_url);
$amp_url = preg_replace('/#038;amp/', '', $amp_url);
$amp_url = str_replace('?lang='.$active_lang, '?amp=1', $amp_url);
$amp_url = add_query_arg( 'lang',$active_lang, $amp_url);
if (is_category() && class_exists('WPSEO_Options') && method_exists('WPSEO_Options', 'get') && WPSEO_Options::get( 'stripcategorybase' ) == true && false == ampforwp_get_setting('ampforwp-category-base-removel-link')) {
if (is_category() && class_exists('RankMath') && RankMath\Helper::get_settings( 'general.strip_category_base' ) == true && false == ampforwp_get_setting('ampforwp-category-base-removel-link')) {
$amp_url = preg_replace('/(.*?)&(.*?)/', '$1&&$2', $amp_url);
if(ampforwp_get_setting('amp-core-end-point') && ampforwp_get_setting('ampforwp-amp-takeover') && is_singular()){
$amp_url = get_the_permalink();
}else if(ampforwp_get_setting('amp-core-end-point') && (ampforwp_is_home() || ampforwp_is_front_page() || ampforwp_is_blog() || is_category() || is_tag() || is_front_page())){
$amp_url = ampforwp_url_controller($amp_url);
$amp_url = apply_filters('ampforwp_modify_rel_canonical',$amp_url);
return esc_url_raw($amp_url);
// AMPHTML when using custom page and then creating a blog page
add_action('amp_init','ampforwp_allow_homepage_as_blog');
function ampforwp_allow_homepage_as_blog() {
if(function_exists('mfn_opts_setup')){
remove_action( 'pre_get_posts', 'mfn_search' );
add_action( 'wp', 'ampforwp_static_blog' , 11 );
function ampforwp_static_blog(){
$modify_canonical = ampforwp_is_front_page();
$get_front_page_reading_settings = get_option('page_on_front');
$get_amp_homepage_support = ampforwp_get_setting('ampforwp-homepage-on-off-support');
if ( 'page' == get_option( 'show_on_front') && is_front_page() && $get_front_page_reading_settings && $get_amp_homepage_support ){
$modify_canonical = true;
if ( true == $modify_canonical && $page >= 2 && is_page() && false == ampforwp_get_setting('amp-core-end-point') ) {
add_filter('ampforwp_modify_rel_canonical','ampforwp_modify_amphtml_static_blog');
function ampforwp_modify_amphtml_static_blog($amp_url) {
$explode_url = $amp_endpoint = $offset = "";
$explode_url = explode('/', $amp_url);
$explode_url = array_flip($explode_url);
unset($explode_url[AMPFORWP_AMP_QUERY_VAR]);
$explode_url = array_flip($explode_url);
$amp_endpoint = array(AMPFORWP_AMP_QUERY_VAR);
$offset = count($explode_url) - 2;
array_splice( $explode_url, $offset, 0, $amp_endpoint );
$amp_url = implode('/', $explode_url);
function ampforwp_home_archive_rel_canonical() {
$amp_url = ampforwp_amphtml_generator();
printf('<link rel="amphtml" href="%s" />', esc_url($amp_url));
if(false==ampforwp_get_setting('hide-amp-version-from-source')){
printf('<meta name="generator" content="%s %s"/>', esc_html__('AMP for WP'), esc_attr(AMPFORWP_VERSION) );
} //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') ) {