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( get_the_ID(),'ampforwp-amp-on-off',true);
if( $ampforwp_amp_post_on_off_meta === 'hide-amp' ) {
//dont Echo anything
} else {
$supported_types = array('post','page');
if ( $redux_builder_amp['ampforwp-custom-type'] ) {
foreach($redux_builder_amp['ampforwp-custom-type'] as $custom_post){
$supported_types[] = $custom_post;
}
}
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if( is_plugin_active( 'amp-woocommerce/amp-woocommerce.php' ) ) {
if( !in_array("product", $supported_types) ){
$supported_types[]= 'product';
}
}
$type = get_post_type();
$supported_amp_post_types = in_array( $type , $supported_types );
if ( is_home() && $wp->query_vars['paged'] >= '2' ) {
$new_url = home_url('/');
$new_url = $new_url . AMP_QUERY_VAR . '/' . $wp->request ;
$amp_url = $new_url ;
}
if ( is_archive() && $wp->query_vars['paged'] >= '2' ) {
$new_url = home_url('/');
$category_path = $wp->request;
$explode_path = explode("/",$category_path);
$inserted = array(AMP_QUERY_VAR);
array_splice( $explode_path, -2, 0, $inserted );
$impode_url = implode('/', $explode_path);
$amp_url = $new_url . $impode_url ;
}
if( is_search() ) {
$current_search_url =trailingslashit(get_home_url())."?amp=1&s=".get_search_query();
$amp_url = untrailingslashit($current_search_url);
}
if( $supported_amp_post_types) {
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;
// Homepage and FrontPage
if($redux_builder_amp['amp-frontpage-select-option'] == 0) {
if ( is_home() ) {
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';
}
}
}
// Archive Pages
if ( is_archive() && $redux_builder_amp['ampforwp-archive-support'] ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/archive.php';
}
if ( $redux_builder_amp['amp-design-selector'] == 3) {
if ( is_search() && $redux_builder_amp['amp-design-3-search-feature'] ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/search.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;
}
//3.5
add_filter( 'amp_post_template_file', 'ampforwp_empty_filter', 10, 3 );
function ampforwp_empty_filter( $file, $type, $post ) {
if ( 'empty-filter' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/empty-filter.php';
}
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/design-manager/empty-filter.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/design-manager/empty-filter.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( is_page() ) { ?>
';
$output .= '';
$output .= '';
$output .= ' ';
echo $output;
}
}
// Above Footer Global
add_action('amp_post_template_footer','ampforwp_footer_advert',8);
add_action('amp_post_template_above_footer','ampforwp_footer_advert',10);
if ( $redux_builder_amp['amp-design-selector'] == 3) {
remove_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('/ ' );
} 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','ampforwp_remove_title_tags');
function ampforwp_remove_title_tags(){
remove_action('amp_post_template_head','amp_post_template_add_title');
add_action('amp_post_template_head','ampforwp_add_custom_title_tag');
function ampforwp_add_custom_title_tag(){
global $redux_builder_amp; ?>
post_title;
echo $title . ' | ' . get_option( 'blogname' ) ;
}
// title for archive pages
if ( is_archive() && $redux_builder_amp['ampforwp-archive-support'] ) {
echo strip_tags(get_the_archive_title( '' ));
echo ' | ';
echo strip_tags(get_the_archive_description( '' ));
}
$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');
} else {
global $wp;
$current_archive_url = home_url( $wp->request );
$current_url_in_pieces = explode('/',$current_archive_url);
$cnt = count($current_url_in_pieces);
if( is_numeric( $current_url_in_pieces[ $cnt-1 ] ) ) {
$site_title .= ' | Page '.$current_url_in_pieces[$cnt-1];
}
}
echo $site_title ;
} ?>
]*/", "", $content_buffer);
$content_buffer = preg_replace("/<\\/?thrive_headline(.|\\s)*?>/",'',$content_buffer);
// Remove Extra styling added by other Themes/ Plugins
$content_buffer = preg_replace('/(