// SEO Canonical Domain Consolidation
// Sets preferred domain for all pages
add_filter( ‚option_siteurl‘, function( $value ) {
return ‚https://chicandchill.de‘;
});
add_filter( ‚option_home‘, function( $value ) {
return ‚https://chicandchill.de/‘;
});
// Force canonical tags
add_action( ‚wp_head‘, function() {
global $wp;
$canonical = ‚https://chicandchill.de‘ . add_query_arg( array(), ‚/‘ . trim( $wp->request, ‚/‘ ) );
echo ‚‚ . „\n“;
}, 2 );
// Redirect www to non-www
add_action( ‚init‘, function() {
if ( isset( $_SERVER[‚HTTP_HOST‘] ) && strpos( $_SERVER[‚HTTP_HOST‘], ‚www.‘ ) === 0 ) {
$non_www_url = str_replace( ‚www.‘, “, $_SERVER[‚HTTP_HOST‘] );
$redirect_url = ‚https://‘ . $non_www_url . $_SERVER[‚REQUEST_URI‘];
wp_redirect( $redirect_url, 301 );
exit;
}
}, 1 );