Skip to content

Instantly share code, notes, and snippets.

Avatar

Nate Holman nholman7

View GitHub Profile
@nholman7
nholman7 / gist:ece1db2e2352d3e1d94d83a9ba30b4e3
Created Feb 27, 2018
Custom Add HTTPS Canonical to HTTP
View gist:ece1db2e2352d3e1d94d83a9ba30b4e3
function custom_canonical() {
if (isset($_SERVER['HTTP']) && $_SERVER['HTTP'] != 'off') {
return "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
} else {
// Yoast SEO will use default canonical for HTTPS version site
}
}
add_filter( 'wpseo_canonical', 'custom_canonical' );
View gist:2664d97eba913933f1610804e876f8a7
<link rel="canonical" href="https://<?php echo $_SERVER['HTTP_HOST']; ?><?php echo parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); ?>" />
View gist:18cdb42fb2a16f24a4bf3ae2400633b7
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Remove Yoast SEO Canonical From All Pages
* Credit: Yoast Team
* Last Tested: Jun 16 2017 using Yoast SEO 4.9 on WordPress 4.8
*/
add_filter( 'wpseo_canonical', '__return_false' );