Conditional Canonical Tags & Disable Yoast Canonical

Functions.php

add_filter( 'wpseo_canonical', '__return_false' );

Header.php

<?php
$reqURL = $_SERVER['REQUEST_URI'];
if (strpos($reqURL, 'free-tips') !== false) {
echo '<link rel="canonical" href="https://example.com.au/free-tips/">';
}elseif (strpos($reqURL, 'category/preparation') !== false) {
echo '<link rel="canonical" href="https://example.com.au/category/preparation/">';
}elseif (strpos($reqURL, 'category/painting-tips') !== false) {
echo '<link rel="canonical" href="https://example.com.au/category/painting-tips/">';
}else{
echo '<link rel="canonical" href="https://example.com.au'.$reqURL.'">';
}

Want a Fast Server Like Mine?

GET VULTR!