Check if you are on the front page with is_front_page()
. The home page (in WordPress the page with the latest posts) can be checked with is_home()
.
You can add this to the header.php
between <head>
and </head>
:
<?php
if ( is_front_page() )
echo '<link rel="canonical" href="' . home_url( "https://wordpress.stackexchange.com/" ) . '" />';
?>