= 1) :
remove_action( 'wp_head', 'ampforwp_home_archive_rel_canonical' );
endif;
}
function ampforwp_home_archive_rel_canonical() {
global $redux_builder_amp;
global $wp;
if( is_attachment() ) {
return;
}
if( is_home() && !$redux_builder_amp['ampforwp-homepage-on-off-support'] ) {
return;
}
if( is_front_page() && ! $redux_builder_amp['ampforwp-homepage-on-off-support'] ) {
return;
}
if ( is_archive() && !$redux_builder_amp['ampforwp-archive-support'] ) {
return;
}
if( is_page() && !$redux_builder_amp['amp-on-off-for-all-pages'] ) {
return;
}
$query_arg_array = $wp->query_vars;
if( in_array( "cpage" , $query_arg_array ) ) {
if( is_front_page() && $wp->query_vars['cpage'] >= '2' ) {
return;
}
if( is_singular() && $wp->query_vars['cpage'] >= '2' ) {
return;
}
}
if ( is_home() || is_front_page() || is_archive() ){
global $wp;
$current_archive_url = home_url( $wp->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( is_singular() && $ampforwp_amp_post_on_off_meta === 'hide-amp' ) {
//dont Echo anything
} else {
$supported_types = array('post','page');
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if( is_plugin_active( 'amp-custom-post-type/amp-custom-post-type.php' ) ) {
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 );
$query_arg_array = $wp->query_vars;
if( array_key_exists( 'paged' , $query_arg_array ) ) {
if ( ( is_home() || is_front_page() ) && $wp->query_vars['paged'] >= '2' ) {
$new_url = home_url('/');
$new_url = $new_url . AMPFORWP_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(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();
}
}
if( is_search() ) {
$current_search_url =trailingslashit(get_home_url())."?amp=1&s=".get_search_query();
$amp_url = untrailingslashit($current_search_url);
}
$amp_url = apply_filters('ampforwp_modify_rel_canonical',$amp_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;
$slug = array();
$current_url_in_pieces = array();
$ampforwp_custom_post_page = ampforwp_custom_post_page();
// Homepage and FrontPage
if ( is_home() ) {
if ( 'single' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/index.php';
if ($redux_builder_amp['amp-frontpage-select-option'] == 1) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/frontpage.php';
}
if ( $ampforwp_custom_post_page == "page" && ampforwp_name_blog_page() ) {
$current_url = home_url( $GLOBALS['wp']->request );
$current_url_in_pieces = explode( '/', $current_url );
if( in_array( ampforwp_name_blog_page() , $current_url_in_pieces ) ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/index.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';
}
// Search pages
if ( is_search() &&
( $redux_builder_amp['amp-design-1-search-feature'] ||
$redux_builder_amp['amp-design-2-search-feature'] ||
$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( $redux_builder_amp['enable-single-social-icons'] == true || AMPFORWP_DM_SOCIAL_CHECK === 'true' ) { ?>
';
$output .= '';
$output .= ' ';
$output .= ' ';
echo $output;
}
}
// Above Footer Global
add_action('amp_post_template_above_footer','ampforwp_footer_advert',10);
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');
// Hook updated
// 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;
}
}
// Below The Title
add_action('ampforwp_below_the_title','ampforwp_below_the_title_advert');
function ampforwp_below_the_title_advert() {
global $redux_builder_amp;
if($redux_builder_amp['enable-amp-ads-5'] == true) {
if($redux_builder_amp['enable-amp-ads-select-5'] == 1) {
$advert_width = '300';
$advert_height = '250';
} elseif ($redux_builder_amp['enable-amp-ads-select-5'] == 2) {
$advert_width = '336';
$advert_height = '280';
} elseif ($redux_builder_amp['enable-amp-ads-select-5'] == 3) {
$advert_width = '728';
$advert_height = '90';
} elseif ($redux_builder_amp['enable-amp-ads-select-5'] == 4) {
$advert_width = '300';
$advert_height = '600';
} elseif ($redux_builder_amp['enable-amp-ads-select-5'] == 5) {
$advert_width = '320';
$advert_height = '100';
} elseif ($redux_builder_amp['enable-amp-ads-select-5'] == 6) {
$advert_width = '200';
$advert_height = '50';
} elseif ($redux_builder_amp['enable-amp-ads-select-5'] == 7) {
$advert_width = '320';
$advert_height = '50';
}
$output = '';
$output .= '
';
$output .= ' ';
$output .= '
';
echo $output;
}
}
// Above Related post
add_action('ampforwp_above_related_post','ampforwp_above_related_post_advert');
function ampforwp_above_related_post_advert() {
global $redux_builder_amp;
if($redux_builder_amp['enable-amp-ads-6'] == true) {
if($redux_builder_amp['enable-amp-ads-select-6'] == 1) {
$advert_width = '300';
$advert_height = '250';
} elseif ($redux_builder_amp['enable-amp-ads-select-6'] == 2) {
$advert_width = '336';
$advert_height = '280';
} elseif ($redux_builder_amp['enable-amp-ads-select-6'] == 3) {
$advert_width = '728';
$advert_height = '90';
} elseif ($redux_builder_amp['enable-amp-ads-select-6'] == 4) {
$advert_width = '300';
$advert_height = '600';
} elseif ($redux_builder_amp['enable-amp-ads-select-6'] == 5) {
$advert_width = '320';
$advert_height = '100';
} elseif ($redux_builder_amp['enable-amp-ads-select-6'] == 6) {
$advert_width = '200';
$advert_height = '50';
} elseif ($redux_builder_amp['enable-amp-ads-select-6'] == 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'], ' ' );
}
}
function ampforwp_custom_yoast_meta_homepage(){
global $redux_builder_amp;
if ($redux_builder_amp['ampforwp-seo-yoast-meta']) {
if(! class_exists('YoastSEO_AMP') ) {
if ( class_exists('WPSEO_Options')) {
if( method_exists('WPSEO_Options', 'get_option')){
$options = WPSEO_Options::get_option( 'wpseo_social' );
if ( $options['twitter'] === true ) {
WPSEO_Twitter::get_instance();
}
if ( $options['opengraph'] === true ) {
$GLOBALS['wpseo_og'] = new WPSEO_OpenGraph;
}
}
}
do_action( 'wpseo_opengraph' );
}//execute only if Glue is deactive
echo strip_tags($redux_builder_amp['ampforwp-seo-custom-additional-meta'], ' ' );
}
}
function ampforwp_add_proper_post_meta(){
$check_custom_front_page = get_option('show_on_front');
if ( $check_custom_front_page == 'page' ) {
add_action( 'amp_post_template_head', 'ampforwp_custom_yoast_meta_homepage' );
if(is_home()){
add_filter('wpseo_opengraph_title', 'custom_twitter_title_homepage');
add_filter('wpseo_twitter_title', 'custom_twitter_title_homepage');
add_filter('wpseo_opengraph_desc', 'custom_twitter_description_homepage');
add_filter('wpseo_twitter_description', 'custom_twitter_description_homepage');
add_filter('wpseo_opengraph_url', 'custom_og_url_homepage');
// This is causing the 2nd debug issue reported in #740
// add_filter('wpseo_twitter_image', 'custom_og_image_homepage');
add_filter('wpseo_opengraph_image', 'custom_og_image_homepage');
}
} else {
add_action( 'amp_post_template_head', 'ampforwp_custom_yoast_meta' );
}
}
add_action('pre_amp_render_post','ampforwp_add_proper_post_meta');
function custom_twitter_title_homepage() {
return esc_attr( get_bloginfo( 'name' ) );
}
function custom_twitter_description_homepage() {
return esc_attr( get_bloginfo( 'description' ) );
}
function custom_og_url_homepage() {
return esc_url( get_bloginfo( 'url' ) );
}
function custom_og_image_homepage() {
if ( class_exists('WPSEO_Options') ) {
$options = WPSEO_Options::get_option( 'wpseo_social' );
return $options['og_default_image'] ;
}
}
/**
* PR by Sybre Waaijer:
* @link https://github.com/ahmedkaludi/accelerated-mobile-pages/pull/761
*
* @since version 0.9.48 :
* 1. Removes unused code.
* 2. Cleaned up code.
* 3. Keeps legacy action in place.
* 4. No longer replaces the title tag.
* 5. Instead, filters the title tag.
* 6. Therefore, it works with all SEO plugins.
* 7. Removed direct Yoast SEO compat -- It's no longer needed.
* 8. Removed unwanted spaces.
* 9. Improved performance.
* 10. Improved security.
* 11. Added support for CPT and attachment pages.
*/
//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() {
return ampforwp_replace_title_tags();
}
function ampforwp_replace_title_tags() {
add_filter( 'pre_get_document_title', 'ampforwp_add_custom_title_tag', 10 );
add_filter( 'wp_title', 'ampforwp_add_custom_title_tag', 10, 3 );
function ampforwp_add_custom_title_tag( $title = '', $sep = '', $seplocation = '' ) {
global $redux_builder_amp;
//* We can filter this later if needed:
$sep = ' | ';
if ( is_singular() ) {
global $post;
$title = ! empty( $post->post_title ) ? $post->post_title : $title;
$site_title = $title . $sep . get_option( 'blogname' );
} elseif ( is_archive() && $redux_builder_amp['ampforwp-archive-support'] ) {
$site_title = strip_tags( get_the_archive_title( '' ) . $sep . get_the_archive_description( '' ) );
}
if ( is_home() ) {
if ( 1 == $redux_builder_amp['amp-frontpage-select-option'] ) {
$ID = $redux_builder_amp['amp-frontpage-select-option-pages'];
$site_title = get_the_title( $ID ) . $sep . get_option( 'blogname' );
} else {
$site_title = get_bloginfo( 'name' ) . $sep . get_option( 'blogdescription' );
$current_archive_url = home_url( $GLOBALS['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 .= $sep . 'Page ' . $current_url_in_pieces[ $cnt - 1 ];
}
}
}
if ( is_search() ) {
$site_title = $redux_builder_amp['amp-translator-search-text'] . ' ' . get_search_query();
}
return esc_html( convert_chars( wptexturize( trim( $site_title ) ) ) );
}
}
add_action('amp_post_template_include_single','ampforwp_update_title_for_frontpage');
function ampforwp_update_title_for_frontpage() {
$check_custom_front_page = get_option('show_on_front');
if ( $check_custom_front_page == 'page' && is_home() ) {
remove_action( 'amp_post_template_head', 'amp_post_template_add_title' );
add_action('amp_post_template_head','ampforwp_frontpage_title_markup');
add_filter('aioseop_title','ampforwp_aioseop_front_page_title');
}
}
// Custom Frontpage title for ALL in one SEO.
function ampforwp_aioseop_front_page_title() {
$sep = ' | ';
return $site_title = get_bloginfo( 'name' ) . $sep . get_option( 'blogdescription' );
}
function ampforwp_frontpage_title_markup () {
$front_page_title = ampforwp_add_custom_title_tag();
$front_page_title = apply_filters('ampforwp_frontpage_title_filter', $front_page_title);
?>
]*/", "", $content_buffer);
$content_buffer = preg_replace("/<\\/?thrive_headline(.|\\s)*?>/",'',$content_buffer);
// Remove Extra styling added by other Themes/ Plugins
$content_buffer = preg_replace('/(