How to Fix Open Graph URL Not Matching Canonical

Modified Date:September 26, 2024
How to Fix Open Graph URL Not Matching Canonical

Ahrefs reported “Open Graph URL not matching canonical” error indicates a mismatch between the canonical URL and the Open Graph URL within a webpage. Ideally, both URLs should be identical for every webpage on your site.

  1. Canonical URL: This specifies the preferred version of a webpage, used by search engines and other systems to avoid duplicate content issues.
  2. Open Graph URL: This is a specific URL embedded within the webpage’s code using Open Graph tags. Social media platforms like Facebook and Twitter use this URL to display previews (title, image, description) when the webpage is shared.
Ahrefs issue Open Graph URL Not Matching Canonical

The Importance of the issue:

Social media platforms use the URL set in og:url. This is crucial to ensure that users are not misled when generating a Facebook card.

How to check the issue:

To check the issue, you can use any browser. Open the source code of the problematic page by right-clicking anywhere on the page and selecting the “View Page Source” or similar option.

Source Code Guide

Check the Canonical URL and Open Graph URL in source code.

Source code

How to Fix Open Graph URL Not Matching Canonical:

If you have encountered this problem in Ahrefs crawl report and are worried about how to solve it, then the following step-by-step guidelines will be helpful for you. Here, you will be guided how to fix this issue in WordPress.

  1. First, go to your Code Snippets plugin. If you haven’t installed the plugin yet, please do so.
  2. Open the Code Snippets plugin and click on “Add New” to create a new snippet.
Code Snippet
Code Snippet Guide

3. In the snippet editor, add the following code:

/* Add this code in snippet */
function update_og_url($url) {
      $url = get_site_url().$_SERVER['REQUEST_URI'];
        return $url;
}
add_filter('wpseo_opengraph_url', 'update_og_url', 10, 1);
How to Fix Open Graph URL Not Matching Canonical

4: After Add the snippet and clear the cache now check the again source code of problematic webpage.

Open Graph URL

Now Canonical and Open Graph URL is same. And the issue is successfully fixed.

Announcement:
If you’re also concerned about such crucial issues, you can get in touch with us to fix your website’s technical issues. Contact us now.

Contact Info



© 2024 3wBiz | All Rights Reserved | Privacy Policy