当前位置: 首页 > Skill >

WordPress API Auto Post 文章自动发布API

WordPress API Auto Post 文章自动发布API

WordPress API Auto Post 文章自动发布API

通过 REST API 使用 RankMath 元字段向 WordPress 发布 SEO 优化文章

2.1.1 2026.11.27 232
获取Skill文件查看使用说明
作 者:林舟 许可证: 更新时间:2026.11.27
本文目录展开

WordPress SEO Publisher

通过 WordPress REST API 发布 SEO 优化文章,自动设置 RankMath Free 版 meta fields(SEO 标题、描述、焦点关键词)。

Requirements

  • python3(无需额外 pip 依赖,仅使用标准库)
  • WordPress 已安装 RankMath SEO Free
  • WordPress 已创建 Application Password
  • WordPress functions.php 中已注册 RankMath meta keys(见下方 WordPress 配置)

Directory Structure

scripts/
├── publish_wp_article.py       # 主发布脚本
docs/
├── wordpress-setup.php         # functions.php 代码片段(需手动添加到 WordPress)

Environment Variables

在 ~/.openclaw/workspace-marketing/.env 中配置:

WP_SITE_URL=https://你的域名
WP_USERNAME=WordPress用户名
WP_APP_PASSWORD=xxxx xxxx xxxx xxxx xxxx xxxx
WP_CATEGORY_ID=Articles分类的ID

执行方式

cd ~/.openclaw/workspace-marketing
export $(cat .env | grep "^WP_" | xargs)
python3 skills/wp-seo-publisher/scripts/publish_wp_article.py '<json_data>'

JSON 参数定义

字段 类型 必填 说明
title String ✅ 文章标题(含关键词,50-60 字符)
content String ✅ 文章 HTML 正文(使用 H2/H3 结构)
excerpt String 推荐 文章摘要,也用作默认 meta description
slug String 推荐 SEO 友好的 URL(英文、连字符分隔)
focus_keyword String 推荐 RankMath 焦点关键词
seo_title String 否 自定义 SEO 标题(留空则用 title)
seo_description String 否 自定义 meta description(留空则用 excerpt)
tags Array 否 标签名称列表(不存在的 tag 会自动创建)
category_id Number 否 分类 ID(留空则用 .env 中的默认值)
status String 否 publish 或 draft(默认 draft)

RankMath 免费版自动处理的 SEO 功能

以下功能 RankMath 会根据文章内容自动处理,无需通过 API 额外设置:

功能 说明
XML Sitemap 新文章自动加入 sitemap,加速搜索引擎收录
Canonical URL 自动生成,防止重复内容问题
Open Graph Tags 自动生成 og:title、og:description、og:image
Twitter Cards 自动生成社交分享卡片
Article Schema 自动添加 Article 结构化数据
Meta Robots 默认 index, follow
Breadcrumbs 自动生成(需在 RankMath 设置中启用)

通过 API 主动设置的字段(3 个)

Meta Key 对应 JSON 字段 作用
rank_math_title seo_title 或 title 搜索结果中显示的标题
rank_math_description seo_description 或 excerpt 搜索结果中显示的描述
rank_math_focus_keyword focus_keyword RankMath 内容评分的焦点关键词

AI Agent 发布工作流

注意:

  • 关键词挖掘阶段已独立,必须委托给 seo-keyword-researcher Skill 处理。
  • 文章撰写与排版阶段已独立,必须委托给 seo-content-writer Skill 处理。

本 Skill (wp-seo-publisher) 仅负责「API 发布」与「日志记录」。

  1. 读取输入 (Input):前往目录 ~/.openclaw/workspace-marketing/seo/seo_articles/,寻找并读取最新时间戳且尚未发布的 JSON 文件(例如 2026-05-06_110000.json)。
  2. 人工确认 (Approval Gate):向用户展示即将发布的文章标题、slug 和 status,必须等待用户明确确认后才执行发布。如果用户未指定 status: "publish",默认以 draft 模式发布。
  3. 执行发布 (Execute):将该 JSON 文件的内容作为参数,传递给 Python 脚本: python3 skills/wp-seo-publisher/scripts/publish_wp_article.py '<读取到的 JSON 内容>'
  4. 标记与记录 (Clean up):
    • 防重复机制:发布成功后,必须将该 JSON 文件重命名,加上 _published 后缀(例如执行 mv 2026-05-06_110000.json 2026-05-06_110000_published.json)。
    • 更新日志:将发布成功的结果与 URL 追加写入 memory/wp-articles-log.md。此日志仅用于本 Skill 的防重复检查和发布审计,不应被其他 Skill 用作数据输入源。

JSON 组装范例

{
  "title": "Top 5 Benefits of Renting Robots for Corporate Events",
  "content": "<h2>Why More Companies Are Choosing Robot Rental</h2><p>In today's competitive event landscape...</p><h2>1. Cost Efficiency</h2><p>Purchasing a service robot can cost...</p><h2>2. Professional Setup & Support</h2><p>When you rent from a professional provider...</p><h2>3. Cutting-Edge Technology</h2><p>Robot technology evolves rapidly...</p><h2>4. Wow Factor for Guests</h2><p>Nothing captures attention quite like...</p><h2>5. Flexibility and Variety</h2><p>Different events call for different robots...</p><h2>Ready to Elevate Your Next Event?</h2><p>Contact us today for a free consultation and quote. <a href='https://example.com/contact'>Get in touch →</a></p>",
  "excerpt": "Discover the top 5 reasons why renting robots for corporate events saves money, impresses guests, and delivers cutting-edge experiences.",
  "slug": "benefits-renting-robots-corporate-events",
  "focus_keyword": "renting robots for corporate events",
  "seo_title": "Top 5 Benefits of Renting Robots for Corporate Events | Your Company",
  "seo_description": "Discover the top 5 reasons why renting robots for corporate events saves money, impresses guests, and delivers cutting-edge experiences.",
  "tags": ["robot rental", "corporate events", "service robots", "event technology"],
  "status": "draft"
}

发布记录格式(memory/wp-articles-log.md)

## 2026-05-07
- **Title**: Top 5 Benefits of Renting Robots for Corporate Events
- **URL**: https://example.com/benefits-renting-robots-corporate-events/
- **Focus Keyword**: renting robots for corporate events
- **Tags**: robot rental, corporate events, service robots, event technology
- **Status**: published

主题库(Agent 轮换使用)

  1. Robot rental benefits for businesses
  2. Industry applications: hospitality
  3. Industry applications: retail
  4. Industry applications: events & exhibitions
  5. Industry applications: healthcare
  6. Industry applications: education
  7. Event planning with service robots
  8. Robot technology trends and innovations
  9. FAQ: robot rental process, pricing, setup
  10. Cost analysis: buying vs renting robots
  11. Customer engagement with robots
  12. Future of service robotics in Hong Kong
  13. How to choose the right robot for your event
  14. Robot safety and insurance considerations
  15. Success stories: robots at corporate events

WordPress 配置(一次性设置)

必要步骤

  1. 安装 RankMath Free → Plugins → Add New → 搜索 Rank Math SEO
  2. 创建 Application Password → Users → Profile → Application Passwords
  3. 注册 meta keys → 将 docs/wordpress-setup.php 中的代码添加到主题 functions.php
  4. 记录分类 ID → Posts → Categories → 找到 Articles 的 ID

返回值

成功时输出:

✅ Article published successfully!
  Post ID:        123
  URL:            https://example.com/your-article-slug/
  Status:         publish
  Focus Keyword:  your keyword

__RESULT_JSON__:{"success":true,"post_id":123,"url":"...","status":"publish",...}

失败时返回非零退出码,并输出错误信息。

注意事项

  1. 首次使用建议用 status: "draft" 测试,在 WordPress 后台确认 RankMath 数据正确
  2. 确保 WordPress 启用 HTTPS,否则 Application Password 不安全
  3. 文章内容必须有实质价值,不要生成低质量 SEO spam
  4. 每篇文章的 slug 必须唯一,避免冲突
  5. focus_keyword 应与文章主题一致,这会影响 RankMath 的内容评分

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,016
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,004
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,002
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,001
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,001
PHP集成RabbitMQ实现消息队列的完整步骤

使用 php-amqplib 库,通过建立连接、声明交换机与队列并绑定,即可在 PHP 中实现消息的发送与消费。

2026.05.24 1,001
Skill 文件
  • SKILL.md
    • WordPress SEO Publisher
    • Requirements
    • Directory Structure
    • Environment Variables
    • 执行方式
    • JSON 参数定义
    • RankMath 免费版自动处理的 SEO 功能
    • 通过 API 主动设置的字段(3 个)
    • AI Agent 发布工作流
      • JSON 组装范例
      • 发布记录格式(memory/wp-articles-log.md)
    • 主题库(Agent 轮换使用)
    • WordPress 配置(一次性设置)
      • 必要步骤
    • 返回值
    • 注意事项
  • 项目或源文件

相关 Skill

更多
Wordpress AEO Autoblogger Wordpress AEO Autoblogger 自主AEO与SEO内容生成与优化引擎,用于规模化业务运营。适用于Codex需执行端到端程序化SEO的场景。
WordPress REST API CLI WordPress REST API CLI OpenClaw 技能,提供 WordPress REST API 命令行接口,用于文章、页面、分类、标签、用户及自定义请求,使用纯 HTTP。
wordpress-ultimate wordpress-ultimate Three env vars. One script. Your agent manages your entire WordPress site — draft-only safety included.
Develop and harden WordPress plugins with lifecycle and security guardrails Develop and harden WordPress plugins with lifecycle and security guardrails 当代理需要构建、重构、保护或打包具有正确激活钩子、设置处理、卸载行为和数据卫生的WordPress插件时,请使用Automattic官方wp-plugin-development技能。这是一个插件工程手册,而不是通用的WordPress列表。
WordPress MCP WordPress MCP 通过AI Engine的MCP(模型上下文协议)管理WordPress网站。用于创建/编辑文章、SEO分析、数据分析、媒体管理、分类操作、社媒排程、多语言内容(Polylang)及任何WordPress管理任务。需安装免费AI Engine插件并启用MCP服务器。适用于WordPress网站管理、内容工作流或WP相关任务。