', esc_url( $amp_url ) );
}
}
// 3. Custom Single and homepage code
// 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/index.php';
}
}
} elseif ($redux_builder_amp['amp-frontpage-select-option'] == 1) {
if ( is_home() || is_archive() ) {
if ( 'single' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/frontpage.php';
}
}
}
// Custom Single file
if ( is_single() || is_page() ) {
if ( 'single' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/single.php';
}
}
return $file;
}
// 4. Custom Style files
add_filter( 'amp_post_template_file', 'mohammed_amp_set_custom_style', 10, 3 );
function mohammed_amp_set_custom_style( $file, $type, $post ) {
if ( 'style' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/style.php';
}
return $file;
}
// 5. Custom Header files
add_filter( 'amp_post_template_file', 'mohammed_amp_set_custom_header', 10, 3 );
function mohammed_amp_set_custom_header( $file, $type, $post ) {
if ( 'header-bar' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/header.php';
}
return $file;
}
// 7. 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;
}
// 9. Add required Javascripts for extra AMP features
add_action('amp_post_template_head','ampforwp_register_additional_scripts');
function ampforwp_register_additional_scripts() {
global $redux_builder_amp; ?>
ID );
} else {
$ampforwp_backto_nonamp = '';
}
?>
';
}
add_action('amp_post_template_footer','ampforwp_main_tag_ends',9);
function ampforwp_main_tag_ends() {
echo '';
}
// 12. Advertisement code
// Below Header Global
add_action('ampforwp_after_header','ampforwp_header_advert');
function ampforwp_header_advert() {
global $redux_builder_amp;
if($redux_builder_amp['enable-amp-ads-1'] == true) {
if($redux_builder_amp['enable-amp-ads-select-1'] == 1) {
$advert_width = '300';
$advert_height = '250';
} elseif ($redux_builder_amp['enable-amp-ads-select-1'] == 2) {
$advert_width = '336';
$advert_height = '280';
} elseif ($redux_builder_amp['enable-amp-ads-select-1'] == 3) {
$advert_width = '728';
$advert_height = '90';
} elseif ($redux_builder_amp['enable-amp-ads-select-1'] == 4) {
$advert_width = '300';
$advert_height = '600';
} elseif ($redux_builder_amp['enable-amp-ads-select-1'] == 5) {
$advert_width = '320';
$advert_height = '100';
} elseif ($redux_builder_amp['enable-amp-ads-select-1'] == 6) {
$advert_width = '200';
$advert_height = '50';
} elseif ($redux_builder_amp['enable-amp-ads-select-1'] == 7) {
$advert_width = '320';
$advert_height = '50';
}
$output = '
';
$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');
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');
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;
}
}
add_action('amp_post_template_footer','ampforwp_google_analytics',11);
function ampforwp_google_analytics() { ?>