Skip to content

Instantly share code, notes, and snippets.

@herbie4
Last active June 23, 2020 08:20
Show Gist options
  • Save herbie4/4d02fcf99086ba7dfe92c9be890c852a to your computer and use it in GitHub Desktop.
Save herbie4/4d02fcf99086ba7dfe92c9be890c852a to your computer and use it in GitHub Desktop.
Yoast WP SEO - change the og:url to the current post url when using canonical url
<?php
// yoast wp seo plugin og:url override
// ---------------------------
// change the og:url to the current post url when using canonical url
// fix for share on instagram and Facebook to use the website url
// not the canonical url
// ---------------------------
add_filter( 'wpseo_opengraph_url', 'hhdev_change_opengraph_url' );
function hhdev_change_opengraph_url( $url ) {
global $post;
return get_permalink($post->ID);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment