# Auto Featured Image by Post Types Using Robolly API and Templates

Discover how to automatically set featured images for post types using Robolly API and templates. Enhance your content with ease!

Canonical: https://www.ruhanirabin.com/code-snippet/auto-featured-image-post-types-using-robolly-api-and-templates/

Dec 30, 2024WPCodeBox

This snippet uses Robolly Templates and API to generate Featured Images for a Specific Post Type. It has WP Admin page inside **Settings > AFI—Robolly.** ![A screenshot of the AFI Robolly Settings page in WordPress displays places where you can enter the Robolly API key and template IDs to automatically create featured images. There are settings for various post types and links to more information about Robolly and donations.](https://cdn.ruhanirabin.com/wp-content/uploads/2024/12/AFI_Robolly_Settings_%E2%80%B9_RuhaniRabin.com_%E2%80%94_WordPress_00799-600x466.png)

## Conditions:

1. Requires **Robolly Template** to be done
2. Requires **Robolly API** key
3. A post with a `published` status, only if there is **_NO featured image already_** attached
4. Setup credentials in **Settings > AFI — Robolly**

## Operation:

1. Set up a Template in Robolly
2. Copy the Template ID and Robolly API Key
3. Set up the preferences
4. Now go to a published post or page
5. Make sure there are no existing-featured images is set to the post
6. Press Save — wait for it to work
7. Refresh the post editor to see the new featured image

## Works with:

1. WP CodeBox
2. FluentSnippets
3. Other Code Snippets Plugins

## Additional Snippets

CHANGELOG: Version 1.2 (2026-01-15) - Added support for extracting first image from post content (per post-type control) - Added minimum image width validation (600px default, configurable per post-type) - Added image parameter name configuration for Robolly templates (per post-type) - Added automatic image dimension detection - Added support for sending images to Robolly API via URL parameter - Enhanced error logging for image extraction process - Added fallback behavior when no suitable image is found - Added version management and automatic settings migration - Per post-type configuration for image extraction feature - Added manual save/update support with duplicate prevention - Plugin now works on save/update events, not just publish - Smart tracking prevents multiple generations for same post - Auto-reset generation flag when featured image is manually deleted - Allow regeneration by simply deleting featured image and saving again Version 1.1 - Added image metadata generation settings - Added support for custom post types - Improved error handling and retry logic Version 1.0 - Initial release   Copy the code and paste it inside your favorite code-snippet plugin.

[View on GitHub](https://raw.githubusercontent.com/ruhanirabin/wpcodebox-snippets/refs/heads/main/snippets/robolly-auto-featured-image-plugin.php)

## Screenshots

![A screenshot of the AFI Robolly Settings page in WordPress displays places where you can enter the Robolly API key and template IDs to automatically create featured images. There are settings for various post types and links to more information about Robolly and donations.](https://cdn.ruhanirabin.com/wp-content/uploads/2024/12/AFI_Robolly_Settings_%E2%80%B9_RuhaniRabin.com_%E2%80%94_WordPress_00799.png)![A screenshot shows a software screen where you can see a hidden API key for the Robolly API, with buttons to either copy or view it. The heading says API key. A red arrow points to the Copy button, making it easier to manage different post types.](https://cdn.ruhanirabin.com/wp-content/uploads/2024/12/Robolly_and_15_more_pages_-_Personal_-_Microsoft%E2%80%8B__00800.png)![Ruhani Rabins promotional banner is advertising a free service for tracking URLs and creating status pages. It works smoothly with the Robolly API. The banner features a gradient background that goes from orange to dark gray, has bold white text, and includes an arrow pointing to the banner on the webpage.](https://cdn.ruhanirabin.com/wp-content/uploads/2024/12/Edit_Page_Get_Your_Own_URL_Monitor__Status_Page__00801.png)![The Robolly screen shows a sidebar with options such as My templates, Datasets, and others. On the right side, you can see a preview of a template with example text. This illustrates how the Robolly API easily adds automatic featured images to different post types.](https://cdn.ruhanirabin.com/wp-content/uploads/2024/12/Robolly_and_15_more_pages_-_Personal_-_Microsoft%E2%80%8B__00802.png)
