0

When a URL is shared on Facebook, Facebook is able to automatically pull a relevant image and the meta description for use in the post.

Would it be possible to code similar functionality into WordPress such that if a URL were added to a custom field within a WordPress post, WordPress would be able to pull in a relevant image and the meta description?

  • Probably. What have you tried so far? – WebElaine Oct 29 '19 at 16:13
  • I have not tried anything. I wasn't sure how it worked so I was hoping for an explanation of the general approach first. – zgall1 Oct 29 '19 at 20:08
0

I believe Facebook uses the Open Graph protocol for this. Basically, a site that provides certain Open Graph meta tags can have the data that these tags refer to appear nicely formatted on Facebook.

Example from the Open Graph protocol site:

<html prefix="og: http://ogp.me/ns#">
<head>
<title>The Rock (1996)</title>
<meta property="og:title" content="The Rock" />
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
...
</head>
...
</html>

You could probably use a similar approach if this suits your use case.

For sites without these tags, Facebook does indicate that:

Without these tags, the Facebook Crawler uses internal heuristics to make a best guess about the title, description, and preview image for your content.

If your question is centered around how this can be achieved, things might get a little more complicated. You could try an approach in which, based on a WordPress post URL, you perform a GET request on the associated blog's REST API that fetches the metadata of that particular post for you.

  • This makes sense. Thank you for the explanation. I guess I'll need to figure out how to use the REST API in the most sensible way. – zgall1 Oct 29 '19 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.