
A custom field for Strapi that allows content editors to fetch Open Graph data from a URL and save it as structured JSON. This enables you to easily create beautiful, data-rich preview cards in your frontend application.
released September 14, 2025
npm install @spencercooley/strapi-plugin-og-pretty-linkA custom field for Strapi that allows content editors to fetch Open Graph data from a URL and save it as structured JSON. This enables you to easily create beautiful, data-rich preview cards in your frontend application.

In your Strapi project, install the plugin from npm:
npm install @spencercooley/strapi-plugin-og-pretty-linkEnable the plugin in your Strapi project by creating or editing the file config/plugins.ts:
// file: config/plugins.ts
export default {
'og-pretty-link': {
enabled: true,
},
};For the image previews in the admin panel to work correctly, you must update your application's Content Security Policy (CSP). This is because the OG images can come from any website.
In config/middlewares.ts, modify the strapi::security middleware to allow images from any http: or https: source:
// file: config/middlewares.ts
export default [
'strapi::logger',
'strapi::errors',
{
name: 'strapi::security',
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
// Allow images from any source for previews
'img-src': ["'self'", 'data:', 'blob:', 'https://market-assets.strapi.io', 'http:', 'https:'],
},
},
},
},
'strapi::cors',
'strapi::poweredBy',
'strapi::query',
'strapi::body',
'strapi::session',
'strapi::favicon',
'strapi::public',
];After configuring the plugin and middleware, rebuild your admin panel and restart the server:
npm run build
npm run developWhile you can add the field via the Content-Type Builder UI, it is recommended to define it directly in your schemas for version control and consistency.
This is the most flexible approach, allowing you to add link previews anywhere in your content.
Step 1: Create the Component Schema
Create a new file at src/components/shared/og-link.json.
Important: Strapi components are organized into categories based on the folder structure inside src/components. In this case, shared is the category name. This allows you to organize your components logically (e.g., shared, page_sections, marketing).
// file: src/components/shared/og-link.json
{
"collectionName": "components_shared_og_links",
"info": {
"displayName": "OG Link",
"icon": "link",
"description": "A component to fetch and display Open Graph link previews."
},
"options": {},
"attributes": {
"data": {
"type": "customField",
"customField": "plugin::og-pretty-link.og-link"
}
}
}Step 2: Add the Component to a Dynamic Zone
In your Content Type's schema (e.g., src/api/article/content-types/article/schema.json), add the newly created component to your dynamiczone's components array.
Notice how "shared.og-link" directly maps to the folder and file you created (shared/og-link.json).
// file: src/api/article/content-types/article/schema.json
{
// ... other schema properties
"attributes": {
// ... other attributes
"blocks": {
"type": "dynamiczone",
"components": [
"shared.media",
"shared.quote",
"shared.rich-text",
"shared.og-link" // <-- Add this line
]
}
}
}If you don't need a dynamic zone, you can add the field directly to any content type's schema.json:
// file: src/api/my-content-type/content-types/my-content-type/schema.json
{
// ... other schema properties
"attributes": {
// ... other attributes
"my_link_preview": {
"type": "customField",
"customField": "plugin::og-pretty-link.og-link"
}
}
}After defining your schemas, restart your Strapi server. The "OG Link" field will now be available in your content editor.
Share your work with the community and get it listed in the Strapi ecosystem for everyone to discover and use.
Submit
