Use this PHP code snippet to customize the canonical URL for your pages and posts, ensuring proper SEO optimization for duplicate content.
add_filter( 'aioseo_canonical_url', function ( $url ) {
if ( is_single() && has_category( 'news' ) ) {
return 'https://example.com/custom-canonical-url/';
}
return $url;
});