Publishing consistently is one of the hardest parts of running a WordPress site. An AI agent can take over the repetitive work: researching topics, drafting articles, formatting them, and pushing them to your site on a schedule. This guide walks through a practical, safe way to set that up, from the first credentials to a fully automated workflow.
What an AI Publishing Agent Actually Does
An AI publishing agent is a small automated pipeline with four parts:
- Trigger – a schedule (for example, every weekday at 9 AM) or an event (a new row in a spreadsheet of topics).
- Generation – an AI model writes the title, body, excerpt, and tags from a topic or brief.
- Formatting – the output is converted to clean HTML or Gutenberg blocks.
- Publishing – the agent sends the post to WordPress through its REST API.
The key point is that WordPress already ships with a REST API, so you don’t need a special plugin to receive posts. You only need credentials and an endpoint.
Step 1: Prepare WordPress for API Access
Create a dedicated user
Don’t use your admin account. Create a new user (for example, ai-author) with the Author or Editor role. This limits the damage if the credentials ever leak, and it makes AI-written posts easy to identify in your dashboard.
Generate an Application Password
Since WordPress 5.6, Application Passwords are built in:
- Log in as your new user and go to Users → Profile.
- Scroll to Application Passwords.
- Enter a name such as “AI Agent” and click Add New Application Password.
- Copy the password right away. WordPress only shows it once.
Your site must use HTTPS for Application Passwords to work by default.
Confirm the REST API works
Visit https://yoursite.com/wp-json/wp/v2/posts in a browser. If you see JSON, the API is reachable. Some security plugins or hosts block the REST API, so check those settings if you get an error.
Step 2: Choose How You Will Build the Agent
There are three common approaches, depending on your comfort with code.
| Approach | Best for | Effort |
|---|---|---|
| No-code automation (Make, Zapier) | Beginners, simple schedules | Low |
| Workflow tools (n8n) | More control, self-hosting, branching logic | Medium |
| Custom script (Python or Node.js) | Full control, custom research and review steps | Higher |
If you’re unsure, start with a no-code tool to prove the idea, then move to a script when you need more control.
Step 3: Build a Simple Agent in Python
Here is a minimal example that generates an article and publishes it as a draft through the REST API. It uses the Anthropic API for writing, but any AI provider works the same way.
import os
import requests
import anthropic
WP_URL = "https://yoursite.com/wp-json/wp/v2/posts"
WP_USER = "ai-author"
WP_APP_PASSWORD = os.environ["WP_APP_PASSWORD"]
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from the environment
def generate_article(topic: str) -> dict:
prompt = (
f"Write a helpful, original blog post about: {topic}.\n"
"Return the title on the first line, then the body in clean HTML "
"using <h2>, <p>, and <ul> tags only."
)
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=2000,
messages=[{"role": "user", "content": prompt}],
)
text = response.content[0].text.strip()
title, _, body = text.partition("\n")
return {"title": title.lstrip("# ").strip(), "content": body.strip()}
def post_to_wordpress(article: dict, status: str = "draft") -> str:
payload = {
"title": article["title"],
"content": article["content"],
"status": status, # draft, pending, or publish
}
r = requests.post(
WP_URL,
json=payload,
auth=(WP_USER, WP_APP_PASSWORD),
timeout=30,
)
r.raise_for_status()
return r.json()["link"]
if __name__ == "__main__":
article = generate_article("Benefits of container gardening for beginners")
print("Created:", post_to_wordpress(article))
Store your Application Password and API key as environment variables, never inside the script or a public repository.
Step 4: Add Categories, Tags, and Images
A basic post is a start, but a good agent also handles metadata:
- Categories and tags – send arrays of IDs in the
categoriesandtagsfields. Look up IDs withGET /wp-json/wp/v2/categories, or create new ones with a POST request. - Excerpt – add an
excerptfield so your theme and search results show a clean summary. - Featured image – upload the file with
POST /wp-json/wp/v2/media, then pass the returned ID asfeatured_mediawhen creating the post. - SEO fields – plugins like Yoast or Rank Math expose their own fields. These often need extra registration before the REST API accepts them, so check your plugin’s documentation.
Step 5: Automate the Schedule
Once the script works, run it automatically:
- Cron job (Linux/macOS):
0 9 * * 1-5 /usr/bin/python3 /path/to/agent.pyruns it every weekday at 9 AM. - GitHub Actions: use a scheduled workflow and store secrets in the repository settings.
- Make, Zapier, or n8n: use the built-in scheduler as the trigger.
To feed the agent topics, keep a Google Sheet or a simple text file of ideas and have the script pick the next unused one.
Step 6: Keep a Human in the Loop
This is the most important step. Fully unattended publishing is risky, because AI can state incorrect facts, repeat itself, or produce text that doesn’t match your voice.
A safer setup:
- Publish everything as draft or pending first.
- Send yourself a notification by email or Slack with a link to the draft.
- Review, fact-check, and edit before pressing Publish.
- Once you trust the output for a specific, low-risk content type, consider auto-publishing only that category.
You can also add an automated review step: a second AI call that checks the draft against a style guide, flags unsupported claims, and scores it before it ever reaches WordPress.
Best Practices for Quality and SEO
- Give the agent a detailed brief. Include your audience, tone, word count, and example articles. Vague prompts produce generic content.
- Ground the content in real sources. Feed in your own notes, product data, or research rather than relying on the model’s memory alone.
- Check for duplicates. Before creating a post, query existing titles so the agent doesn’t write the same topic twice.
- Add original value. Search engines reward helpful, experience-based content. Add your own examples, data, and opinions during review.
- Disclose AI use where appropriate. Some audiences and platforms expect transparency, and rules vary by region and industry.
Security Checklist
- Use a dedicated low-privilege user, not an administrator.
- Keep credentials in environment variables or a secrets manager.
- Revoke the Application Password immediately if it is ever exposed.
- Rate-limit the agent and set a maximum number of posts per day.
- Log every post the agent creates so you can audit or roll back changes.
Troubleshooting Common Problems
| Problem | Likely cause and fix |
|---|---|
| 401 Unauthorized | Wrong username or Application Password, or the site isn’t using HTTPS |
| 403 Forbidden | The user role lacks permission, or a security plugin or firewall blocks the REST API |
404 on /wp-json/ |
Permalinks set to “Plain”; switch to “Post name” under Settings → Permalinks |
| HTML appears as raw text | The content wasn’t sent as HTML; check your formatting step |
| Categories not applied | You sent names instead of numeric category IDs |
Conclusion
Setting up an AI agent to post on WordPress comes down to a few reliable building blocks: an Application Password, the REST API, an AI model for drafting, and a scheduler to run it all. Start small with draft-only posts and a human review step, then expand automation as you gain confidence in the quality. Done well, you get a consistent publishing rhythm without giving up editorial control.



