WebDev24X7
All articles
AI Automation

How to Automate WordPress Publishing with n8n

Learn how to set up a complete n8n workflow that auto-publishes WordPress posts, sends notifications, and syncs to social media — saving hours every week.

RK
Rajat Kumar 1 March 2025 8 min read

If you manage a WordPress site and manually create posts, schedule social shares, and send email notifications, you are burning time on work a machine should do. This guide walks through a complete n8n WordPress automation workflow that drafts content, publishes it through the WordPress REST API, enriches it with AI, and syndicates it to social media — all without touching a server or writing backend code. n8n is an open-source workflow automation tool, and paired with the WordPress REST API it becomes a genuinely powerful auto-publish WordPress engine that can save hours each week.

What You'll Build

By the end of this tutorial you will have an n8n workflow that:

  1. Triggers on a schedule or an incoming webhook
  2. Uses the OpenAI node to generate a title and summary
  3. Creates a draft or published post via the WordPress REST API
  4. Branches with an IF node to draft-for-review versus auto-publish
  5. Syndicates the post to Slack and social media
  6. Catches failures with a dedicated error workflow

The same pattern scales from a personal blog to a busy editorial team. If you would rather have it built and handed over, our AI Automation service does exactly this for clients.

Prerequisites

Before you start, make sure you have:

  • An n8n instance, either self-hosted or on n8n.cloud
  • A WordPress site running version 5.6 or later with the REST API enabled (it is on by default)
  • An administrator or editor user on WordPress to generate credentials
  • An OpenAI API key if you want AI-generated titles and summaries
  • API credentials for any social or messaging services you plan to connect

Step 1: Enable WordPress REST API Authentication

The WordPress REST API lives at /wp-json/wp/v2/ on your site and lets external tools read and write posts over HTTP. To write posts you must authenticate, and the cleanest built-in method is an Application Password.

Create an Application Password

  1. In WordPress, go to Users, then your profile.
  2. Scroll to the Application Passwords section.
  3. Enter a name such as "n8n automation" and click Add New.
  4. Copy the generated password immediately — WordPress shows it only once.

Application Passwords use HTTP Basic Auth. n8n combines your username and the application password into a Base64 token. You can preview the header format like this:

# username:application-password encoded for the Authorization header
echo -n "YOUR_USERNAME:YOUR_APP_PASSWORD" | base64
# Then requests use: Authorization: Basic <encoded-value>

Store the credential in n8n

In n8n, open Credentials and create a new HTTP Basic Auth or WordPress API credential. Enter your WordPress username and the application password. Never hardcode this in a node — keeping it in the Credentials store means it is encrypted and reusable across workflows.

Verify connectivity with a quick read request before building anything else:

curl -u "YOUR_USERNAME:YOUR_APP_PASSWORD" \
  https://YOUR_SITE.com/wp-json/wp/v2/posts?per_page=1

A JSON array in the response confirms authentication works.

Step 2: Add the Trigger

Every n8n workflow starts with a trigger. You have two practical options for an auto-publish WordPress pipeline.

Option A — Schedule Trigger

Use the Schedule Trigger node when you generate content on a cadence, for example drafting a post every morning from a queue in a database or Google Sheet. Set it to run daily at a fixed hour.

Option B — Webhook Trigger

Use the Webhook node when an external system should kick off publishing, such as a form submission, a CMS event, or another app. WordPress can also call n8n on publish by adding a small hook to your theme:

// functions.php — notify n8n whenever a post is published
add_action('publish_post', function ($post_id) {
  $post = get_post($post_id);
  wp_remote_post('YOUR_N8N_WEBHOOK_URL', [
    'body'    => wp_json_encode([
      'id'    => $post_id,
      'title' => $post->post_title,
      'url'   => get_permalink($post_id),
    ]),
    'headers' => ['Content-Type' => 'application/json'],
  ]);
});

For this tutorial we will assume the Schedule Trigger, since the goal is to have n8n create the content rather than react to it.

Step 3: Generate a Title and Summary with AI

Add the OpenAI node right after your trigger. This is where a plain content idea becomes a polished, SEO-friendly post. Feed it the raw topic or draft body and ask for a structured response.

Configure a Chat model and use a prompt similar to this:

You are an editorial assistant. Given the draft below, return:
- an SEO title under 60 characters
- a 155-character meta summary
- three relevant tags
Draft: {{ $json.draftBody }}
Return valid JSON only.

Ask the model to return JSON so downstream nodes can read individual fields cleanly. If you request plain text, add a Set or Code node afterward to parse it. Keep temperature low, around 0.3 to 0.5, so titles stay on-brand and predictable.

Step 4: Shape the Payload with a Set Node

Add a Set node to assemble the exact fields the WordPress REST API expects. This keeps your HTTP request clean and makes the data easy to inspect during test runs.

{
  "title":   "{{ $json.aiTitle }}",
  "content": "{{ $json.draftBody }}",
  "excerpt": "{{ $json.aiSummary }}",
  "status":  "draft"
}

Setting status to draft first is deliberate — it lets you preview AI output in the WordPress editor before anything goes live. We will make the draft-versus-publish decision explicit in the next step.

Step 5: Decide Draft vs Publish with an IF Node

Not every post should go live automatically. Add an IF node to route content based on a condition — for example, publish only when a confidence flag or an "approved" field is true, and otherwise leave it as a draft for human review.

Example IF condition:

Value 1:  {{ $json.autoApprove }}
Operation: is equal to
Value 2:  true

The true branch sends status: publish, and the false branch keeps status: draft. This single node is the safety valve that keeps an aggressive automation from posting something half-baked to your live site.

Step 6: Create the Post via the WordPress REST API

Now the core action. You can use the native WordPress node (choose the Post resource and the Create operation) or an HTTP Request node for full control. The HTTP Request approach maps directly onto the REST API and is worth understanding.

Configure the HTTP Request node like this:

Method:        POST
URL:           https://YOUR_SITE.com/wp-json/wp/v2/posts
Authentication: your saved WordPress / Basic Auth credential
Body Content:  JSON

And send a body such as:

{
  "title":   "{{ $json.title }}",
  "content": "{{ $json.content }}",
  "excerpt": "{{ $json.excerpt }}",
  "status":  "{{ $json.status }}",
  "categories": [12],
  "tags": [34, 56]
}

The API returns the created post as JSON, including its id and link. Capture those — the rest of the workflow uses the live URL. Categories and tags are referenced by their numeric IDs; you can fetch those once from /wp-json/wp/v2/categories and reuse them.

Step 7: Syndicate to Slack and Social Media

With the post live, fan out the announcement. Add a Slack node to alert your team channel:

🚀 Published: {{ $json.title }}
{{ $json.link }}

Then chain social nodes. Add the Twitter/X node with a Create Tweet operation and the LinkedIn node with a Create Post operation. Reference the freshly returned URL so links are always correct:

{{ $json.title }} — read it here: {{ $json.link }} #webdev #wordpress

To avoid tripping platform rate limits, drop a small Wait node between social posts, and store every social credential in n8n Credentials rather than in the node itself.

Step 8: Add Error Handling

Automations fail quietly unless you plan for it. Create a separate workflow that starts with an Error Trigger node, then attach your main workflow to it under Settings, Error Workflow. Route failures to a dedicated Slack channel so you hear about problems immediately:

❌ Workflow failed: {{ $json.workflow.name }}
Error: {{ $json.execution.error.message }}
Time: {{ $now.toISO() }}

For the HTTP Request node specifically, enable Retry On Fail with two or three attempts and a short delay. Transient network blips and brief REST API timeouts then resolve themselves without paging you.

Step 9: Schedule and Go Live

Finally, set the cadence. If you used the Schedule Trigger, confirm its cron expression matches your editorial rhythm — daily, weekly, or several times a day. Toggle the workflow to Active, and n8n handles execution from then on. Run a manual test first with a throwaway draft to confirm the full chain works end to end before trusting it with real content.

What You Can Automate Next

Once the core pipeline runs reliably, extend it:

  • Generate a featured image with an AI image model and set it via the media endpoint
  • Auto-translate posts and publish to language-specific sites
  • Pull topic ideas from a Google Sheet or Notion database queue
  • Purge your CDN or Cloudflare cache right after each publish
  • Compile published posts into a weekly digest email
  • Cross-post to a headless Next.js front end using the same REST data

Because n8n is visual and node-based, each of these is an add-on branch rather than a rewrite.

Wrapping Up

A well-built n8n WordPress automation turns publishing from a manual chore into a reliable, hands-off pipeline: AI drafts the title and summary, the WordPress REST API creates the post, an IF node decides draft versus live, and social syndication plus error handling round it out. The result is a genuine auto-publish WordPress system you can trust to run on schedule.

If you want this designed, built, and maintained for your business, that is our specialty — see our work and learn about the team behind it. Ready to ship your own automation? Get in touch and we will scope a custom n8n workflow tailored to how your content actually flows.

RK
Rajat Kumar
Founder, WebDev24x7

Full-stack developer with 10+ years building enterprise web platforms and AI automation systems — WordPress, Drupal, Next.js, and n8n.

Work with me