Press ESC to close

Or check our Popular Categories...
Howdy! How can we help you?
Categories
< All Topics
Print

How To Add Canonical Tag In WordPress

How to Add Canonical Tag in WordPress?

Canonical tags are important for search engine optimization as they help to prevent duplicate content from being penalized. In WordPress, adding a canonical tag is very easy and can be done in several ways.

Method 1: Using Yoast SEO Plugin
If you are using Yoast SEO plugin, adding a canonical tag is pretty straightforward. First, install and activate the plugin if you haven’t already. Then, go to your WordPress dashboard and navigate to SEO > Search Appearance > Content Types. Under the “Content Types” tab, click on the post type for which you want to add a canonical tag. Next, scroll down to the “Advanced” section and look for the “Canonical URL” field. Enter the canonical URL for the post and click on “Save Changes”. Yoast SEO will now automatically add the canonical tag to the header of the post.

Method 2: Using Theme Functions File
If you don’t want to use a plugin, you can add a canonical tag to your WordPress theme’s functions file. To do this, go to Appearance > Theme Editor from your WordPress dashboard. In the right-hand panel, look for the “functions.php” file and click on it. Add the following code to the end of the file:

`add_action(‘wp_head’, ‘my_canonical’);`

`function my_canonical() {`

`if (is_singular()) {`

`global $wp_the_query;`

`if ($wp_the_query->post->ID != $wp_the_query->queried_object_id) {`

`echo ‘

Comments

Leave a Reply

Table of Contents