Opening Problem Statement
Meet Sarah, a digital marketer juggling multiple campaigns who struggles with the overwhelming task of consistently producing high-quality blog posts for her company’s WordPress site. Each week, she spends hours meticulously researching, writing, formatting, and finding appropriate images, only to publish with a manual process prone to errors and inconsistencies. Sarah often finds herself stuck in repetitive routines, losing precious time that could be better spent on strategy and growth.
This tedious manual effort not only drains her creativity but also slows down the content pipeline, leading to missed opportunities and irregular post schedules that impact SEO and audience engagement.
What This Automation Does
This unique n8n automation workflow revolutionizes Sarah’s content creation and publishing routine by harnessing AI and seamless integrations to:
- Automatically generate full SEO-structured articles using OpenAI’s GPT-4o model with detailed headings, paragraphs, and lists formatted with HTML tags.
- Extract relevant, specific image search keywords from the article content to enhance visual appeal.
- Retrieve high-quality landscape images dynamically from the Pexels API based on these keywords.
- Save generated articles along with extracted keywords to Google Sheets for easy record-keeping and further analysis.
- Publish posts directly to WordPress with full HTML content, including inline images and automatic featured image setting (via recommended FIFU plugin).
- Randomize publishing times with controlled delays up to 6 hours to simulate natural posting patterns and avoid spammy behavior.
With this automation, Sarah can eliminate manual writing and publishing bottlenecks, saving hours weekly, increasing post volume, and improving SEO consistency effortlessly.
Prerequisites ⚙️
- n8n account (self-hosting option available for full control and privacy; see Hostinger guide)
- OpenAI API key with access to GPT-4o model for content generation 🧠
- Google Sheets account with OAuth2 credentials 📊
- Pexels API key for high-quality free images 📁
- WordPress site with API access and the Featured Image from URL (FIFU) plugin installed and configured for automatic featured image setting 📧
Step-by-Step Guide
Step 1: Create your n8n workflow
Log into your n8n instance and start a new workflow. You’ll be building a chain that begins with a scheduling trigger to automate post creation.
Step 2: Set up the Schedule Trigger node
Click “Nodes” → “Add Node” → “Schedule Trigger”. Configure it to trigger your workflow weekly on specific days (e.g., Tue, Thu, Sun at noon). This controls when new posts get generated.
You should see a node labeled “3. Schedule Your Posts” with interval settings for your chosen days and time.
Common mistake: Forgetting to set trigger days will cause the workflow not to run as expected.
Step 3: Add Processing Delay with random wait
This automation introduces variability to posting time to avoid robotic patterns.
Add a Code node named “Processing Delay” and paste this JavaScript code:
const delay = Math.floor(Math.random() * (6 * 60 * 60 * 1000)); // random delay 0-6 hour
return {
json: {
delay: delay,
delay_minutes: Math.round(delay / 60000),
delay_hours: (delay / 3600000).toFixed(2)
}
};
This script generates a random delay between 0 and 6 hours in milliseconds.
Next, add a Wait node to pause the workflow based on this delay. Use an expression for the amount field referencing {{$json["delay"] / 1000}} to convert milliseconds to seconds.
Step 4: Generate AI content with OpenAI node
Add the OpenAI node (LangChain’s OpenAI integration). Paste your prompt instructing GPT-4o to generate a fully formatted HTML article, including specific keywords for image searching.
The prompt template includes:
- A request for H1, H2, and H3 headings
- Paragraphs with proper
tags - Lists using
/ - Extraction of 3-5 specific image keywords
For example:
{
"title": "{Your trend-driven article title}",
"content": "{Full HTML article}",
"keywords": ["keyword1", "keyword2", "keyword3"]
}
Common mistake: Forgetting to format output as JSON can cause downstream errors.
Step 5: Save generated data to Google Sheets
Connect your Google Sheets node configured to append to a sheet named “Sheet1” with columns: title, content, and Image search keyword.
Map these fields respectively from the OpenAI node output:
title→{{ $json.message.content.title }}content→{{ $json.message.content.content }}Image search keyword→{{ $json.message.content.keywords.join("+") }}
You should see successful new rows appended after running this step.
Step 6: Retrieve a matching image from Pexels
Add an HTTP Request node, setting method to GET, url to:
https://api.pexels.com/v1/search?per_page=1&orientation=landscape&query={{ $json["Image search keyword"] }}
Include a header with key Authorization and your Pexels API key. This call fetches the top landscape image for your keywords.
Expect a JSON response with image URLs accessible via:
{{ $json.photos[0].src.landscape }}
Step 7: Create and publish WordPress posts with images
Add the WordPress node and configure it with your WordPress API credentials.
Set the title field to:
= {{ $('Save to Sheet').item.json['title'] }}And build the content field using an HTML string that includes the retrieved Pexels image displayed full width, followed by the article content:
.item.json.photos[0].src.landscape }})
{{ $node['Save to Sheet'].json['content'] }}Ensure your WordPress site uses the FIFU plugin with auto featured media to set the featured image automatically.
Publish posts with the status set to publish to go live immediately.
Customizations ✏️
- Adjust publication frequency: Change the schedule trigger node to run daily or monthly instead of weekly to fit your content calendar.
- Modify AI prompt: Edit the OpenAI prompt to target different niches or styles, such as informational, persuasive, or technical writing.
- Use multiple images: Extend the HTTP Request node to retrieve and embed multiple images from Pexels for richer posts.
- Change output status: Configure the WordPress node’s status field to draft instead of publish if you want manual approval before posting.
- Expand keyword extraction: Enhance AI prompt to output additional metadata like tags or categories for WordPress posts.
Troubleshooting 🔧
Problem: WordPress posts are published without images.
Cause: FIFU plugin not installed or auto featured media setting is disabled.
Solution: Install the Featured Image from URL (FIFU) plugin on WordPress and enable Auto > Set Featured Media Automatically from Content under settings.
Problem: Google Sheets data not appending.
Cause: Incorrect sheet name or column mismatch.
Solution: Verify your Google Sheets document ID and make sure column headers match exactly to title, content, and Image search keyword.
Problem: OpenAI node returns errors or no output.
Cause: API key misconfiguration or incorrect prompt JSON formatting.
Solution: Check OpenAI credentials and ensure prompt output is valid JSON matching the specified format.
Pre-Production Checklist ✅
- Confirm all API credentials for Google Sheets, OpenAI, Pexels, and WordPress are correctly added in n8n.
- Test running the OpenAI node separately to verify valid article generation.
- Validate Google Sheets connection and confirm columns and sheet name are as expected.
- Run HTTP Request to Pexels with example keywords to confirm image retrieval succeeds.
- Test WordPress node on a draft post for validation before going live.
- Verify the Schedule Trigger timings and confirm workflow publishing settings.
Deployment Guide
Once tested, activate the schedule trigger node to start automated weekly post creation. Monitor initial runs using n8n’s execution logs to confirm posts generate and publish without errors.
Set workflow to save manual executions for audit and rollback if needed. Adjust schedule or AI prompt based on user feedback and SEO performance metrics to continually refine content effectiveness.
FAQs
Q: Can I use other image APIs besides Pexels?
A: Yes, you can replace the HTTP Request node with any API that returns image URLs, adjusting query and headers accordingly.
Q: Does this consume OpenAI credits quickly?
A: Content generation for long, detailed articles uses more tokens, so monitor your OpenAI usage to balance cost and output volume.
Q: Is my WordPress content secure?
A: Yes, all API credentials are stored securely within your n8n instance. Use self-hosting for enhanced security control.
Q: Can this handle high volume posting?
A: Yes, with proper schedule configuration and API rate limits observed, scalability is manageable.
Conclusion
By setting up this n8n workflow, Sarah transformed her content production process from manual, error-prone toil to smooth, efficient automation. She saves countless hours weekly by automatically generating SEO-friendly articles enriched with relevant images and publishing them on her WordPress site with randomized timing for natural engagement.
This workflow not only boosts productivity but also helps maintain consistent quality and visual appeal, leading to better SEO and user retention. Next, consider expanding automation by integrating social media sharing or newsletter distribution to amplify your content reach and impact.