Strange, _yoast_wpseo_meta-robots-noindex isn't a hook on hookr.io.
Do you know of a script to remove Yoast's output of rel=canonical on noindex pages?
Strange, _yoast_wpseo_meta-robots-noindex isn't a hook on hookr.io.
Do you know of a script to remove Yoast's output of rel=canonical on noindex pages?
Not sure if there are any plugins out there that do this. But a simple function to remove the canonical URL like below seems to work based on my tests.
function wpse282643()
{
global $post;
// Check if WPSEO plugin is active and bail immediately if not (this is just a sample check)
if ( ! defined( 'WPSEO_VERSION' ) ) {
return;
}
// Check if current page/post has noindex set
$noindex = \WPSEO_Meta::get_value( 'meta-robots-noindex', $post->ID );
if ( '1' === $noindex ) {
// Remove canonical URL
remove_action( 'wpseo_head', [ \WPSEO_Frontend::get_instance(), 'canonical' ], 20 );
}
}
add_action( 'template_redirect', 'wpse282643', 99 );