Tips, WordPress

Fix AMP Plugin Not Validating Due to HTTPS Plugin

If you’re like us you’re excited to get Accelerated Mobile Pages working on your site. However, you might also be running into a validation error such as “The mandatory tag ‘amphtml engine v0.js script’ is missing or incorrect”.

After lots of troubleshooting we determined that the very outdated WordPress HTTPS (SSL) Plugin was causing issues. If you can find an alternative to the plugin that would be your easiest fix. However, if you’re in the same boat as us and need only certain pages on your site to be HTTPS then here is a code snippet to add to your themes function.php file. The only change you need to make is to change the Page ID, the one in the example is 126, to whatever the page ID is for the page you want to be secure.

add_action( ‘template_redirect’, ‘fb_ssl_template_redirect’, 1 );
function fb_ssl_template_redirect() {

if ( is_page( 126 ) && ! is_ssl() ) {

if ( 0 === strpos($_SERVER[‘REQUEST_URI’], ‘http’) ) {
wp_redirect(preg_replace(‘|^http://|’, ‘https://’, $_SERVER[‘REQUEST_URI’]), 301 );
exit();
} else {
wp_redirect(‘https://’ . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’], 301 );
exit();
}
} else if ( !is_page( 126 ) && is_ssl() && !is_admin() ) {

if ( 0 === strpos($_SERVER[‘REQUEST_URI’], ‘http’) ) {
wp_redirect(preg_replace(‘|^https://|’, ‘http://’, $_SERVER[‘REQUEST_URI’]), 301 );
exit();
} else {
wp_redirect(‘http://’ . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’], 301 );
exit();
}
}
}

Related posts

mega888 apk