AI Image Generation and WordPress Media Media Upload - n8n Workflow

Use this powerful n8n workflow to automatically generate featured images via Leonardo AI and instantly upload them to your WordPress media library. Perfect for automated content pipelines.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Content managers and bloggers seeking to automate featured image creation.

  • Developers building headless WordPress content pipelines.

  • Users looking for advanced n8n templates integrating AI services and CMS platforms.

  • Anyone needing a robust n8n node setup for asynchronous API handling.

Overview

Generating unique, high-quality images for blog posts can be a time-consuming manual step. This sophisticated n8n workflow solves this by fully automating the process using state-of-the-art AI generation.

The core value provided by this n8n template is seamless integration: an incoming request triggers an image generation job in Leonardo AI. Crucially, the n8n flow handles the required waiting period for the asynchronous AI job to complete, downloads the resulting image, and uses the WordPress API to upload the file, tagging it with a relevant filename (based on the provided slug). This specific n8n workflow dramatically accelerates content creation, ensuring every post has a unique featured image without manual intervention.

How it Works

This automation is designed to be executed by another system or n8n workflow, making it highly modular. Here is the step-by-step logical flow:


  1. Trigger and Input: The n8n workflow is initialized, receiving the necessary prompt for the image and the content slug (for naming the output file) as inputs.

  2. AI Generation Request: An HTTP Request n8n node calls the Leonardo AI API to start a new image generation job, passing the user-defined prompt.

  3. Aysnchronous Wait: Since image generation takes time, the workflow uses a Wait n8n node to pause execution for 1 minute. This is essential for handling the asynchronous nature of the Leonardo AI API.

  4. Generation Status Check: After the wait period, another HTTP Request n8n node polls the Leonardo AI API using the job ID to retrieve the URL of the newly generated image.

  5. Download Image: A third HTTP Request n8n node fetches the image data using the URL obtained in the previous step, converting it into binary data ready for upload.

  6. WordPress Upload: The key action happens here. A dedicated HTTP Request n8n node, configured with WordPress API credentials, uploads the binary image data to the WordPress media endpoint. It dynamically sets the filename using the input slug via an expression (img-{{ $('Code1').item.json.slug }}.jpg).

  7. Output Final URL: The final Code n8n node extracts the newly created WordPress media URL (the guid.raw) and returns it, completing the primary function of this robust n8n template.

Installation Guide

To deploy and utilize this n8n template, follow these steps:


  1. Import: Copy the entire n8n workflow JSON provided and paste it into your n8n instance via the 'New' menu > 'Import from JSON'.

  2. Leonardo AI Setup: You will need two credentials for Leonardo AI:

Set up a 'HTTP Header Auth' credential with your Leonardo AI Bearer Token.
Ensure the associated 'httpHeaderAuth' credential is named correctly (e.g., 'Header Auth - leonardo ai') and linked to the HTTP Request nodes used for generation and status checking.

  1. WordPress Setup: Configure the 'Upload image2' n8n node with a 'WordPress API' credential. This credential requires the base URL of your WordPress site, and credentials (username/password or application password) with media upload permissions.

  2. Testing: Execute the workflow manually using the 'When clicking ‘Execute workflow’' n8n trigger to test with sample data, providing a 'prompt' and 'slug' to ensure successful generation and upload. Review the output of the final n8n node for the image URL.

Node Details

Execute Workflow Trigger: Acts as the primary n8n trigger when this workflow is called by another n8n workflow, accepting prompt and slug variables.
Code1 (Code n8n node): A simple intermediary code n8n node to structure the input data before sending the API call.
HTTP Request1 (Leonardo Generate): Initiates the image generation process, utilizing the input prompt. This n8n node sends a POST request to the Leonardo AI /generations endpoint.
Wait (n8n node): Pauses the execution for 1 minute, allowing the asynchronous image generation job to complete before moving to the polling step. This is vital core logic flow control.
HTTP Request2 (Leonardo Status Check): Polls the Leonardo API to retrieve the generation results using the generated job ID. This n8n node ensures the image is ready before downloading.
HTTP Request3 (Download Image): Fetches the generated image file data. This n8n node converts the data into binary format for the subsequent WordPress upload.
Upload image2 (HTTP Request n8n node): Uploads the binary image data to your WordPress media library using authorized WordPress API credentials. It uses dynamic data from the initial n8n trigger to set the filename.
Code (Code n8n node): Extracts and structures the final WordPress URL of the uploaded media file for easy consumption by subsequent n8n nodes or workflows.

Related n8n Workflows

Free

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by

AI and Automation developer. Im implementing n8n and ai tools to automate marketing and sales in companies

Featured*