Back to Blog

How I Built a WordPress Plugin for AI Image Generation in One Evening with Claude Code

Sergey Nesmachny
Sergey Nesmachny
04.02.2026
5 min read
Share:
How I Built a WordPress Plugin for AI Image Generation in One Evening with Claude Code
Listen to this article
0:00 / 0:00

TL;DR: Tired of wasting time finding illustrations for blog posts. Built a plugin that generates featured images with one click inside WordPress. Freepik gives you $5 credit on signup — enough for 100-250 images for free.


The Problem: Illustrations Eat Your Time

Anyone who runs a blog knows this pain: you write the post, proofread it, format it — then spend another 30 minutes searching for the right image.

My options before:

  • Stock photos — look the same on every website, boring
  • Canva — good, but extra steps: open, design, export, upload
  • DALL-E / Midjourney — great quality, but clunky workflow: generate separately, download, upload to WordPress
  • Manual design — best results, but unrealistic for every post

I wanted something simple: click a button in WordPress → image is generated and set as featured image.


The Solution: Custom Plugin + Freepik API

Why Freepik:

  1. 6 quality models — from HyperFlux (ultra-fast) to Flux 2 Pro (premium quality)
  2. Output format choice — WebP, AVIF, JPEG, PNG
  3. Simple API — clear documentation, logical endpoints
  4. $5 free credit — Freepik gives you $5 on signup, enough for 100-250 generations
  5. Fair pricing — from ~$0.02 per image

Building with Claude Code

I built the entire plugin in one evening using Claude Code. The process:

  1. Described what I wanted: “WordPress plugin, metabox in editor, Generate button, Freepik API call, save as featured image”
  2. Claude generated the basic structure
  3. A few iterations to refine: settings page, model selection, category styles
  4. Testing and fixes

Total time: ~4 hours from idea to working plugin.


What the Plugin Does

🎨 AI Model Selection

The plugin supports 6 models for any use case and budget:

ModelBest ForQualitySpeed
MysticIllustrations, flat designExcellentMedium
Flux DevGeneral purposeGoodFast
Flux Pro 1.1Maximum qualityPremiumSlow
Flux 2 ProLatest premiumPremiumMedium
Flux 2 TurboFast premiumPremiumFast
HyperFluxSpeed priorityGoodUltra Fast

My picks: Mystic for blog illustrations, HyperFlux when I need something quick.

🖼️ Output Formats

Choose the image format that fits your needs:

FormatBest ForFile Size
WebPModern browsers (recommended)Small
AVIFLatest browsersSmallest
JPEGMaximum compatibilityMedium
PNGTransparency supportLarge

Recommendation: WebP offers the best balance of quality and file size.

📐 Image Formats

  • 1:1 — social media
  • 4:3 — classic
  • 2:1 — blog headers (recommended)
  • 16:9 — video thumbnails
  • 9:16 — stories

🎯 Smart Prompts

The plugin automatically builds prompts from:

  • Post title
  • Category
  • Excerpt (first 100 characters)
  • Configured style for the category

Example system prompt:

Create a professional blog header image for an article titled "{title}". 
Style: {style_description}. 
Include elements: {elements}. 
Mood: {mood}. 
Category: {category}.

🏷️ Category Styles

Configure unique visual styles for each blog category:

Category: "taxes"
Colors: "deep blue, gold accents, corporate feel"
Elements: "documents, calculator, charts"
Mood: "professional, trustworthy"

Now all posts in “Taxes” category will have a consistent visual style.

⚡ Auto-Generation

Optional: the plugin can automatically generate an image when a post is published if no featured image is set.


How It Looks

A metabox appears in the WordPress editor called “AI Image Generator”:

  1. See a style preview based on post category
  2. Click “Generate Image”
  3. Wait 10-30 seconds
  4. Image is automatically set as featured image

Don’t like the result? The “Regenerate” button creates a new variation.


Results

Several examples of the plugin’s performance on a finance website

Gallery image 1
1 / 7

appears in the WordPress editor called “AI Image Generator”:

  1. See a style preview based on post category
  2. Click “Generate Image”
  3. Wait 10-30 seconds
  4. Image is automatically set as featured image

Don’t like the result? The “Regenerate” button creates a new variation.

Installation & Setup

Step 1: Get Freepik API Key

  1. Sign up at freepik.com/api
  2. Bonus: Freepik credits you $5 on signup
  3. Copy your API key from the dashboard

Step 2: Install the Plugin

# Option 1: Clone from GitHub
cd wp-content/plugins/
git clone https://github.com/nesmachny/freepik-featured-image-generator.git

# Option 2: Download ZIP and upload via WordPress admin

Step 3: Configure

  1. Activate the plugin in WordPress
  2. Go to Settings → AI Image Generator
  3. Paste your API key
  4. Choose default model
  5. Configure category styles (optional)

Economics: What Does It Cost?

Starting balance: $5 (free on signup)

Cost per generation (approximate):

  • HyperFlux: ~$0.02 (cheapest)
  • Flux Dev: ~$0.03
  • Mystic: ~$0.04
  • Flux 2 Turbo: ~$0.05
  • Flux 2 Pro: ~$0.06
  • Flux Pro 1.1: ~$0.08

$5 gets you:

  • ~250 images with HyperFlux
  • ~160 images with Flux Dev
  • ~100 images with Mystic
  • ~60 images with Flux Pro 1.1

For a small blog (2-4 posts per week), the free $5 lasts 6-12 months. After that — pennies per post.


REST API for Automation

The plugin provides REST API for integrations:

# Generate image for a post
POST /wp-json/aifig/v1/generate/{post_id}

# Custom prompt
POST /wp-json/aifig/v1/custom
{
  "prompt": "Futuristic cityscape with flying cars",
  "post_id": 123
}

Connect to n8n, Zapier, or your own scripts.


Tips for Better Results

Works well:

  • Abstract concepts
  • Illustrations and flat design (Mystic model)
  • Landscapes and architecture
  • Technology imagery

Works less well:

  • Text in images (often garbled)
  • Specific human faces
  • Highly detailed diagrams

Pro tip: Anti-text

In the latest version (v1.1.1), I added automatic “no text, no letters, no words” instruction to prompts — this significantly improved results.


Summary

Problem: Spending 30+ minutes finding illustrations for each post

Solution: WordPress plugin + Freepik API + Claude Code

Result:

  • Generation in 10-30 seconds
  • 6 AI models + 4 output formats (WebP/AVIF/JPEG/PNG)
  • Consistent style per category
  • $5 free to start (100-250 images)
  • Full control via settings

Links


Do you use AI for image generation? What tools work best for you? Drop a comment or reach out on Telegram.

Sergey Nesmachny

Written by

Sergey Nesmachny

Share: