Answers.Body: <p><a href="https://www.drupal.org/project/block_query" rel="nofollow noreferrer">Block Conditional Visibility by URI Query Parameters</a> deals with the specific contribution page selection issue, but I'm still struggling to insert the meta tags into the head of the page as required.</p>
  
  <p>I've tried just adding it in a block, but Facebook doesn't pick up the tags outside the head, it seems. I've tried javascript <a href="https://stackoverflow.com/questions/1900874/how-to-add-anything-in-head-through-jquery-javascript">like this</a> but that doesn't seem to work.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-19T20:17:35.720Z
Answers.LastActivityDate: 2019-12-19T20:17:35.720Z
Answers.UserDisplayName: Lars SG
Answers.Body: <p>I wrote an extension <a href="https://civicrm.org/extensions/ogp" rel="nofollow noreferrer">ogp</a> that detects some patterns in event/contribution/profile pages, and uses that information to build meta tags.</p>
  <p>The <a href="https://lab.civicrm.org/extensions/ogp/-/blob/master/README.md" rel="nofollow noreferrer">README</a> has a bit more details about how the extension works. The idea is to make it &quot;just work&quot;, without too much fiddling (i.e. it's fairly limited), but I'm very open to suggestions on how we could improve this.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-04T00:47:31.693Z
Answers.Text: Interesting. I think for us, the ideal would be just to add these fields (og:description and og:image) to contribution page settings, event settings, etc. perhaps with a fall back to what you use now. But that's probably a bigger project!
Answers.UserDisplayName: Lars SG
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-31T15:29:26.403Z
Answers.LastActivityDate: 2020-07-31T15:29:26.403Z
Answers.UserDisplayName: bgm
Answers.Body: <p>If you're willing to write your own drupal module you should be able to do it with <a href="https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_html_head/7.x" rel="nofollow noreferrer">drupal_add_html_head</a> in <a href="https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_init/7.x" rel="nofollow noreferrer">hook_init</a>. I haven't tested that. If not hook_init then maybe in <a href="https://api.drupal.org/api/drupal/includes%21theme.inc/function/template_preprocess_html/7.x" rel="nofollow noreferrer">hook_preprocess_html</a>. You would need to parse the url to get the <code>id=</code> parameter and that would tell you which contribution page.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-19T20:12:50.943Z
Answers.Text: Would prefer to find a solution that is a little simpler.
Answers.UserDisplayName: Lars SG
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-19T20:04:27.873Z
Answers.LastActivityDate: 2019-12-19T20:04:27.873Z
Answers.UserDisplayName: Demerit
Body: <p>It would be very useful to be able to set specific social meta tags for specific contribution pages, but I can't seem to find any way to do this (definitely not in CiviCRM, there doesn't seem to be a module to do this in Drupal 7).</p>
  
  <p>The idea would be to set og:image and twitter:image for specific contribution pages, which is fairly important for donation pages. Right now, it doesn't appear that these tags are set at at all; Facebook and Twitter just use the top image on the page.</p>
  
  <p>Two challenges here that I see: 
  1) I can't add content to a specific contribution page, only to /civicrm/contribute/transact, which adds to all contribution pages.
  2) I can't add content in the head of the page.</p>
  
  <p>Is there a clever way to make this work?</p>
  
Tags: <contribution-page><social-media>
Title: How to set specific social meta tags for specific contribution pages
ThreadText: # How to set specific social meta tags for specific contribution pages
  
  (Asked by: username_0 on 2019-12-19)
  
  It would be very useful to be able to set specific social meta tags for specific contribution pages, but I can't seem to find any way to do this (definitely not in CiviCRM, there doesn't seem to be a module to do this in Drupal 7).
  
  The idea would be to set og:image and twitter:image for specific contribution pages, which is fairly important for donation pages. Right now, it doesn't appear that these tags are set at at all; Facebook and Twitter just use the top image on the page.
  
  Two challenges here that I see:
  1) I can't add content to a specific contribution page, only to /civicrm/contribute/transact, which adds to all contribution pages.
  2) I can't add content in the head of the page.
  
  Is there a clever way to make this work?
  
  **Tags:** contribution-page, social-media
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2019-12-19. Score: 1
  
  [Block Conditional Visibility by URI Query Parameters](https://www.drupal.org/project/block_query) deals with the specific contribution page selection issue, but I'm still struggling to insert the meta tags into the head of the page as required.
  
  I've tried just adding it in a block, but Facebook doesn't pick up the tags outside the head, it seems. I've tried javascript [like this](https://stackoverflow.com/questions/1900874/how-to-add-anything-in-head-through-jquery-javascript) but that doesn't seem to work.
  
  
  ---
  
  ### Answer by username_1 on 2020-07-31. Score: 1
  
  I wrote an extension [ogp](https://civicrm.org/extensions/ogp) that detects some patterns in event/contribution/profile pages, and uses that information to build meta tags.
  
  The [README](https://lab.civicrm.org/extensions/ogp/-/blob/master/README.md) has a bit more details about how the extension works. The idea is to make it "just work", without too much fiddling (i.e. it's fairly limited), but I'm very open to suggestions on how we could improve this.
  
  > **Comments:**
  > **username_0**: Interesting. I think for us, the ideal would be just to add these fields (og:description and og:image) to contribution page settings, event settings, etc. perhaps with a fall back to what you use now. But that's probably a bigger project!  
  
  ---
  
  ### Answer by username_2 on 2019-12-19. Score: 1
  
  If you're willing to write your own drupal module you should be able to do it with [drupal\_add\_html\_head](https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_html_head/7.x) in [hook\_init](https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_init/7.x). I haven't tested that. If not hook\_init then maybe in [hook\_preprocess\_html](https://api.drupal.org/api/drupal/includes%21theme.inc/function/template_preprocess_html/7.x). You would need to parse the url to get the `id=` parameter and that would tell you which contribution page.
  
  > **Comments:**
  > **username_0**: Would prefer to find a solution that is a little simpler.  
  
  ---
  
  