How to Build an AI Agent for WordPress (3 Methods)

·

·



You don’t need to build an AI agent from scratch. With the right tools, you can connect an AI assistant to your WordPress sites in under 30 minutes—no machine learning expertise required.

What We’re Building

By the end of this guide, you’ll have an AI agent that can:

  • Create, edit, and publish WordPress posts
  • Manage pages, categories, and media
  • Update plugins and site settings
  • Query content and generate reports
  • Handle WooCommerce products and orders
  • Execute complex multi-step workflows

All through natural language. Tell it what you want; it figures out how.

Choose Your Path

Three ways to build a WordPress AI agent, from easiest to most customizable:

Approach Difficulty Time Best For
Claude Desktop + MCP Easy 15 min Personal use, quick setup
OpenClaw Medium 30 min Always-on agent, automation
Custom (Python/Node) Advanced Hours Full control, custom logic

Option 1: Claude Desktop + MCP (Easiest)

Use Anthropic’s official Claude app with MCP to connect directly to WordPress.

Step 1: Set Up WordPress

  1. Install the MCP Adapter plugin on your WordPress site
  2. Go to Users → Your Profile
  3. Scroll to Application Passwords
  4. Create a new password (name it “Claude MCP”)
  5. Copy the password—you won’t see it again

Step 2: Configure Claude Desktop

  1. Download Claude Desktop
  2. Open Settings → Developer → Edit Config
  3. Add your WordPress site:
{
  "mcpServers": {
    "my-wordpress": {
      "command": "npx",
      "args": [
        "-y",
        "@anthropic/mcp-wp-client",
        "https://yoursite.com/wp-json/mcp/mcp-adapter-default-server"
      ],
      "env": {
        "WP_USER": "your-username",
        "WP_APP_PASSWORD": "xxxx xxxx xxxx xxxx xxxx xxxx"
      }
    }
  }
}

Step 3: Start Using It

  1. Restart Claude Desktop
  2. Click the 🔌 icon to verify the connection
  3. Start giving commands:
  • “Show me all draft posts”
  • “Create a new post about [topic]”
  • “What plugins need updates?”
  • “Add a featured image to my latest post”

Done. You now have a WordPress AI agent.


Option 2: OpenClaw (Always-On Agent)

OpenClaw runs as a background service, perfect for agents that need to operate continuously or respond to messages.

Step 1: Install OpenClaw

npm install -g openclaw
openclaw init

Step 2: Configure Your AI Provider

Add your API key to the config:

# ~/.openclaw/openclaw.json
{
  "providers": {
    "anthropic": {
      "apiKey": "sk-ant-..."
    }
  },
  "defaultModel": "anthropic/claude-sonnet-4"
}

Step 3: Add WordPress MCP Server

{
  "mcp": {
    "servers": {
      "wordpress": {
        "command": "npx",
        "args": [
          "-y", 
          "@anthropic/mcp-wp-client",
          "https://yoursite.com/wp-json/mcp/mcp-adapter-default-server"
        ],
        "env": {
          "WP_USER": "your-username",
          "WP_APP_PASSWORD": "xxxx xxxx xxxx xxxx"
        }
      }
    }
  }
}

Step 4: Create Your Agent Persona

Edit ~/.openclaw/workspace/SOUL.md:

# WordPress Content Agent

You manage WordPress sites for content creation and maintenance.

## Capabilities
- Create and publish blog posts
- Optimize content for SEO
- Maintain site health
- Generate reports

## Style
- Professional but efficient
- Always confirm before publishing
- Summarize actions taken

Step 5: Run Your Agent

openclaw gateway start

Your agent now runs in the background. Connect via CLI, Slack, Telegram, or other channels.


Option 3: Custom Build (Full Control)

For developers who want complete control over the agent’s behavior.

Python with LangChain

from langchain_anthropic import ChatAnthropic
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.tools import tool
import requests

# WordPress API wrapper
class WordPressAPI:
    def __init__(self, url, user, password):
        self.url = url
        self.auth = (user, password)
    
    def get_posts(self, status="publish"):
        r = requests.get(
            f"{self.url}/wp-json/wp/v2/posts",
            params={"status": status},
            auth=self.auth
        )
        return r.json()
    
    def create_post(self, title, content, status="draft"):
        r = requests.post(
            f"{self.url}/wp-json/wp/v2/posts",
            json={"title": title, "content": content, "status": status},
            auth=self.auth
        )
        return r.json()

wp = WordPressAPI(
    "https://yoursite.com",
    "username",
    "xxxx xxxx xxxx xxxx"
)

@tool
def list_posts(status: str = "publish") -> str:
    """List WordPress posts by status (publish, draft, pending)."""
    posts = wp.get_posts(status)
    return "\n".join([f"- {p['title']['rendered']} (ID: {p['id']})" for p in posts])

@tool  
def create_post(title: str, content: str) -> str:
    """Create a new WordPress post as a draft."""
    post = wp.create_post(title, content)
    return f"Created draft: {post['title']['rendered']} (ID: {post['id']})"

# Build the agent
llm = ChatAnthropic(model="claude-sonnet-4-20250514")
tools = [list_posts, create_post]
agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools)

# Use it
result = executor.invoke({
    "input": "Create a blog post about AI trends in 2026"
})
print(result["output"])

Node.js with Vercel AI SDK

import { anthropic } from '@ai-sdk/anthropic';
import { generateText, tool } from 'ai';
import { z } from 'zod';

const wpApi = {
  baseUrl: 'https://yoursite.com/wp-json/wp/v2',
  auth: Buffer.from('user:password').toString('base64')
};

const result = await generateText({
  model: anthropic('claude-sonnet-4-20250514'),
  tools: {
    listPosts: tool({
      description: 'List WordPress posts',
      parameters: z.object({
        status: z.enum(['publish', 'draft']).default('publish')
      }),
      execute: async ({ status }) => {
        const res = await fetch(`${wpApi.baseUrl}/posts?status=${status}`, {
          headers: { Authorization: `Basic ${wpApi.auth}` }
        });
        return res.json();
      }
    }),
    createPost: tool({
      description: 'Create a WordPress post',
      parameters: z.object({
        title: z.string(),
        content: z.string()
      }),
      execute: async ({ title, content }) => {
        const res = await fetch(`${wpApi.baseUrl}/posts`, {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
            Authorization: `Basic ${wpApi.auth}`
          },
          body: JSON.stringify({ title, content, status: 'draft' })
        });
        return res.json();
      }
    })
  },
  prompt: 'Create a blog post about remote work productivity tips'
});

console.log(result.text);

Adding More Capabilities

Once your basic agent works, expand it:

Multi-Site Management

Add multiple WordPress sites to your MCP config. The agent can operate across all of them:

“Update plugins on all production sites and report any issues.”

Scheduled Tasks

With OpenClaw, set up cron jobs for automated work:

  • Daily content audits
  • Weekly security reports
  • Monthly analytics summaries

Memory

Give your agent persistent memory so it remembers previous work, your preferences, and context across sessions.

External Integrations

Add more MCP servers:

  • Filesystem — Read local files for content
  • Google Drive — Pull from shared docs
  • Slack — Receive commands, send reports
  • GitHub — Manage theme/plugin repositories

Best Practices

  • Start with drafts — Let AI create drafts, you review before publishing
  • Use staging first — Test on a staging site before production
  • Limit permissions — Create WordPress users with minimal required capabilities
  • Log actions — Keep records of what the agent does
  • Set guardrails — Define what the agent should ask permission for

Next Steps

Now that you have a WordPress AI agent:

  1. Try basic content operations (list posts, create drafts)
  2. Experiment with bulk operations (update categories, add meta descriptions)
  3. Build workflows (research → write → publish → promote)
  4. Add more tools and integrations

Full WordPress MCP Setup Guide →


Related Guides


Recommended Posts