It’s a recent news: Facebook does not allo anymore to change the title and description of a shared link. This is a bad news for who is used to change the title directly while sharing.

Probably Facebook is focusing in having only one source of information for a shared page, the page itself, to avoid misleading shares where the title of the page is changed to something totally different. Or just to make it easy for Facebook to rescrap and update the shared information.

With Yoast SEO plugin you can change the meta title for Facebook directly in the post but the only thing I’m interested on is to remove the postfix in the title with the site name. Doing this for each post would be impossible, too much work.

And Yoast SEO has not an option where to set the template for the Facebook meta title as for the general meta title.

Anyway there is a simple solution: filtering automatically the generated og:title metatag and remove the postfix, if present.

Few lines of code are required:

add_filter('wpseo_opengraph_title', 'my_wpseo_opengraph_title');
 
function my_wpseo_opengraph_title($title) {
  $sep = WPSEO_Utils::get_title_separator();
  $pos = strrpos($title, $sep);
  if ($pos > 0) {
    $title = substr($title, 0, $pos);
  }
  return $title;
}

The code add a filter to the WordPress SEO generated meta title for Facebook, search the configured separator from the end of the string and remove the postfix. The coude should be enough safe and can be easily added to the functions.php file of your child theme.

If you need a plugin to incorporate this code in your blog, let me know.

Similar Posts

2 Comments

  1. Hi there, we are using your plugin for adwords tags and also Yoast for our SEO. I am just wondering how we can fix up the facebook image previews as the two aren’t compatible. I have tried enabling the facebook through Yoast and I keep getting an error. Currently it’s disabled but I don’t get the image previews. Please advise how this can be fixed up?
    Thanks.

Leave a Reply