# Dynamic open graph and twitter images in meta tags of topic page when image is not present in topic

**URL:** <https://meta.discourse.org/t/dynamic-open-graph-and-twitter-images-in-meta-tags-of-topic-page-when-image-is-not-present-in-topic/65684>\
**Category:** Development\
**Created:** [5. Juli 2017 um 19:16 UTC](https://meta.discourse.org/t/dynamic-open-graph-and-twitter-images-in-meta-tags-of-topic-page-when-image-is-not-present-in-topic/65684 "2017-07-05T19:16:07Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![net\_deamon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/net_deamon/32/70126_2.png) [@net\_deamon](https://meta.discourse.org/u/net_deamon)\
**Post date:** [6. Juli 2017 um 15:03 UTC](https://meta.discourse.org/t/dynamic-open-graph-and-twitter-images-in-meta-tags-of-topic-page-when-image-is-not-present-in-topic/65684/4 "2017-07-06T15:03:53Z")

</div>

Thank you @eviltrout. I am still learning ruby, but what I understand is I have to override the summary method in TopicView class (using `add_to_class`, as you suggested), change the excerpt to my own string containing img tag. Is my understanding correct?

```
def summary
    return nil if desired_post.blank?
    # TODO, this is actually quite slow, should be cached in the post table
    excerpt = desired_post.excerpt(500, strip_links: true, text_entities: true)
    (excerpt || "").gsub(/\n/, ' ').strip
  end

```

---

_[View the full topic](https://meta.discourse.org/t/dynamic-open-graph-and-twitter-images-in-meta-tags-of-topic-page-when-image-is-not-present-in-topic/65684)._
