Skip to content

Instantly share code, notes, and snippets.

View nholman7's full-sized avatar

Nate Holman nholman7

View GitHub Profile
@nholman7
nholman7 / gist:ece1db2e2352d3e1d94d83a9ba30b4e3
Created February 27, 2018 00:01
Custom Add HTTPS Canonical to HTTP
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' );
<link rel="canonical" href="https://<?php echo $_SERVER['HTTP_HOST']; ?><?php echo parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); ?>" />
@nholman7
nholman7 / gist:18cdb42fb2a16f24a4bf3ae2400633b7
Created February 26, 2018 23:57
Remove Yoast SEO canonical
<?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' );