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?
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?
Share Improve this question asked Oct 29, 2019 at 16:02 zgall1zgall1 672 silver badges10 bronze badges 2- Probably. What have you tried so far? – WebElaine Commented Oct 29, 2019 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 Commented Oct 29, 2019 at 20:08
1 Answer
Reset to default 0I 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/title/tt0117500/" />
<meta property="og:image" content="http://ia.media-imdb/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.