The og:url meta tag was added in #983512: New meta tags, but it cannot be overridden on a per-node basis. The URL should be a text field that can be overridden just like Title or Summary.

I can hear you thinking, why in the world would you want to replace the node URL for og:url?

There's one particular reason: if you have a webform that redirects to a thank you page after submission, the og:url on the thank you page will, of course, refer to the thank you page.

So, let's say I have a webform node at /survey, and after submitting the survey form, the user is redirected to /thanks-completing-our-survey. If they click a Facebook Like button on that page, they will be sharing the 'thank you' page instead of the actual survey form. It would be preferrable if the admin could override the URL meta tag, so that the URL field on the 'thank you' page would be set to the path of the survey node.

Comments

pal4life’s picture

Here is another example.
On this page , http://www.dosomething.org/programs/awards we would like the wall to have a different url than the one in template but it is not possible since we cannot edit it on per node basis. Also the og:image needs to be custom.

hiddentao’s picture

Added a new hook in latest dev release: og_tag_render_alter

Documentation in opengraph_meta_test_module.module

/**
   * Implements hook_og_tag_render_alter().
   *
   * @param $node the node whose tag is being rendered.
   * @param $name the name of the OG tag being rendered, e.g. title, image.
   * @param $value the value of the OG tag being rendered.
   *
   * @return the altered value to render for the given tag.
   */
supermoos’s picture

How can I use this to change the url proptery to eg. example.com? I looked in opengraph_meta_test_module.module, and then I added this to my template.php file:

function hook_og_tag_render_alter($node, $name, $value){
return "testurl";
}

This is not working, could anyone point me in the right direction?

BrockBoland’s picture

@supermoos: Since it's a hook, it needs to be implemented in a module. You'll need to create a new module, put the function in the .module file, and replace hook with the name of your module. So, if you call the module og_url_override.module, for example, the contents of the file would look like this:


/**
 * Implements hook_og_tag_render_alter().
 *
 * @param $node the node whose tag is being rendered.
 * @param $name the name of the OG tag being rendered, e.g. title, image.
 * @param $value the value of the OG tag being rendered.
 *
 * @return the altered value to render for the given tag.
 */
function og_url_override_og_tag_render_alter($node, $name, $value) {
  return 'bananaphone';
}
rwohleb’s picture

The hook lets me fix the frontage URL as described in #1496008: og:url has wrong value for site frontpage.

  • hiddentao committed 511990b on 7.x-2.x
    Issue #1283234 by hiddentao: Added "og_tag_render_alter hook" for...
torotil’s picture

Issue summary: View changes
Status: Active » Fixed

Seems that this has been implemented / committed long ago.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.