Canonical URLs in WordPress

how to add canonical tag in Wordpress without plugin
To add the canonical URLs in Wordpress, first copy the following code into the functions.php file: Then go to the desired post and create a custom field called canonical, write the canonical URL in its value field, and update the post.