WordPress Publisher Skill技能使用说明
2026-03-29
新闻来源:网淘吧
围观:20
电脑广告
手机广告
WordPress发布器
使用REST API直接将内容发布到WordPress站点,支持完整的古腾堡区块格式化、自动分类选择、SEO标签生成和预览功能。
完整工作流程概述
1. CONNECT → Authenticate with WordPress site
2. ANALYZE → Load categories from site, analyze content for best match
3. GENERATE → Create SEO-optimized tags based on content
4. CONVERT → Transform markdown/HTML to Gutenberg blocks
5. PREVIEW → Create draft and verify rendering
6. PUBLISH → Publish or schedule the post
7. VERIFY → Confirm live post renders correctly
步骤1:连接设置
获取凭证
向用户请求:
- WordPress站点URL(例如,
https://example.com) - WordPress用户名
- 应用程序密码(非普通密码)
如何创建应用程序密码
引导用户:
- 进入WordPress管理后台的用户 → 个人资料页面
- 滚动到应用程序密码部分
- 输入名称:
Claude发布器 - 点击添加新应用密码
- 复制生成的密码(仅显示一次,带空格)
测试连接
from scripts.wp_publisher import WordPressPublisher
wp = WordPressPublisher(
site_url="https://example.com",
username="admin",
password="xxxx xxxx xxxx xxxx xxxx xxxx" # Application password
)
# Test connection
user_info = wp.test_connection()
print(f"Connected as: {user_info['name']}")
步骤2:加载并选择分类
从网站自动加载分类
# Get all categories from the WordPress site
categories = wp.get_categories_with_details()
# Returns list like:
# [
# {'id': 1, 'name': 'Uncategorized', 'slug': 'uncategorized', 'count': 5},
# {'id': 2, 'name': 'Tutorials', 'slug': 'tutorials', 'count': 12},
# {'id': 3, 'name': 'Cloud Hosting', 'slug': 'cloud-hosting', 'count': 8},
# ]
智能分类选择
系统分析内容并选择最合适的分类:
# Analyze content and suggest best category
suggested_category = wp.suggest_category(
content=article_content,
title=article_title,
available_categories=categories
)
# Or let user choose from available options
print("Available categories:")
for cat in categories:
print(f" [{cat['id']}] {cat['name']} ({cat['count']} posts)")
分类选择逻辑
- 精确匹配- 标题/内容包含分类名称
- 关键词匹配- 分类别名与主题关键词匹配
- 父级分类- 若无匹配则回退至更宽泛的父级分类
- 新建分类- 若无合适分类则新建(需用户批准)
步骤3:生成SEO优化标签
自动标签生成
生成提升谷歌搜索可见度的标签:
# Generate tags based on content analysis
tags = wp.generate_seo_tags(
content=article_content,
title=article_title,
max_tags=10
)
# Returns list like:
# ['n8n hosting', 'workflow automation', 'self-hosted n8n',
# 'affordable hosting', 'docker deployment', 'node.js hosting']
标签生成规则
- 主要关键词- 始终作为第一个标签包含
- 次要关键词- 包含2-3个相关术语
- 长尾关键词- 包含3-4个特定短语
- 实体标签- 包含提及的产品/品牌名称
- 主题标签- 包含更广泛的类别术语
在WordPress中创建/获取标签
# Get or create all tags, returns list of tag IDs
tag_ids = wp.get_or_create_tags(tags)
步骤4:将内容转换为古腾堡区块
Markdown 转 Gutenberg
from scripts.content_to_gutenberg import convert_to_gutenberg
# Convert markdown content
gutenberg_content = convert_to_gutenberg(markdown_content)
支持的转换
| Markdown | 古腾堡区块 |
|---|---|
# 标题 | wp:heading |
**加粗** | <strong>在段落中 |
- 列表项 | wp:list |
1. 有序 | wp:list {"ordered":true} |
``代码````wp:code | > 引用 |
wp:quote |  |
wp:image | | 表格 | |
wp:table | 表格转换(对AI内容至关重要) |
表格使用适当的Gutenberg结构进行转换:
步骤5:发布前预览
# Input markdown:
| Feature | Plan A | Plan B |
|---------|--------|--------|
| Price | $10 | $20 |
# Output Gutenberg:
<!-- wp:table -->
<figure class="wp-block-table"><table>
<thead><tr><th>Feature</th><th>Plan A</th><th>Plan B</th></tr></thead>
<tbody><tr><td>Price</td><td>$10</td><td>$20</td></tr></tbody>
</table></figure>
<!-- /wp:table -->
创建预览草稿
验证预览
# Create as draft first
result = wp.create_draft(
title="Article Title",
content=gutenberg_content,
categories=[category_id],
tags=tag_ids,
excerpt="Auto-generated or custom excerpt"
)
post_id = result['post_id']
preview_url = result['preview_url']
edit_url = result['edit_url']
预览检查清单
# Fetch preview page to verify rendering
preview_content = wp.fetch_preview(post_id)
# Check for issues
issues = wp.validate_rendered_content(preview_content)
if issues:
print("Issues found:")
for issue in issues:
print(f" - {issue}")
标题显示正确
- 所有标题渲染正常(H2、H3、H4)
- 表格渲染格式正确
- 列表显示正确(项目符号和编号)
- 代码块具有语法高亮
- 图片加载正常(如果有)
- 链接可点击
- 分类显示正确
- Category shows correctly
- 文章中的标签显示
第六步:发布文章
发布草稿
# After preview approval, publish
result = wp.publish_post(post_id)
live_url = result['live_url']
或直接创建并发布
# Full publish workflow in one call
result = wp.publish_content(
title="Article Title",
content=gutenberg_content,
category_names=["Cloud Hosting"], # By name, auto-resolves to ID
tag_names=["n8n", "hosting", "automation"],
status="publish", # or "draft", "pending", "private", "future"
excerpt="Custom excerpt for SEO",
slug="custom-url-slug"
)
定时发布文章
# Schedule for future publication
from datetime import datetime, timedelta
publish_date = datetime.now() + timedelta(days=1)
result = wp.publish_content(
title="Scheduled Post",
content=content,
status="future",
date=publish_date.isoformat()
)
第七步:验证已发布文章
检查线上文章
# Verify the published post
verification = wp.verify_published_post(post_id)
print(f"Live URL: {verification['url']}")
print(f"Status: {verification['status']}")
print(f"Categories: {verification['categories']}")
print(f"Tags: {verification['tags']}")
常见问题及解决方法
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 表格无法渲染 | 缺少图像包装器 | 使用正确的wp:table区块结构 |
| 代码未高亮显示 | 缺少语言属性 | 添加{"language":"python"}到代码块 |
| 图片无法显示 | URL错误或缺少媒体文件 | 先上传至WordPress,使用媒体ID |
| 标签未显示 | 主题不显示标签 | 检查主题设置或使用不同主题 |
完整示例工作流
from scripts.wp_publisher import WordPressPublisher
from scripts.content_to_gutenberg import convert_to_gutenberg
# 1. Connect
wp = WordPressPublisher(
site_url="https://xcloud.host",
username="admin",
password="xxxx xxxx xxxx xxxx"
)
# 2. Load categories and select best match
categories = wp.get_categories_with_details()
best_category = wp.suggest_category(content, title, categories)
# 3. Generate SEO tags
tags = wp.generate_seo_tags(content, title, max_tags=10)
# 4. Convert to Gutenberg
gutenberg_content = convert_to_gutenberg(markdown_content)
# 5. Create draft and preview
draft = wp.create_draft(
title="7 Best n8n Hosting Providers in 2026",
content=gutenberg_content,
categories=[best_category['id']],
tags=wp.get_or_create_tags(tags)
)
print(f"Preview: {draft['preview_url']}")
# 6. After verification, publish
result = wp.publish_post(draft['post_id'])
print(f"Published: {result['live_url']}")
快速参考
API端点
| 资源 | 端点 |
|---|---|
| 文章 | /wp-json/wp/v2/posts |
| 页面 | /wp-json/wp/v2/pages |
| 分类 | /wp-json/wp/v2/categories |
| 标签 | /wp-json/wp/v2/tags |
| 媒体 | /wp-json/wp/v2/media |
文章状态
| 状态 | 描述 |
|---|---|
发布 | 已上线且可见 |
草稿 | 已保存但不可见 |
待处理 | 等待审核 |
私有 | 仅管理员可见 |
未来 | 计划稍后发布 |
必需文件
scripts/wp_publisher.py- 主发布类scripts/content_to_gutenberg.py- Markdown/HTML 转换器references/gutenberg-blocks.md- 区块格式参考
错误处理
| 错误代码 | 含义 | 解决方案 |
|---|---|---|
| 401 | 凭据无效 | 检查用户名和应用程序密码 |
| 403 | 权限不足 | 用户需要编辑者或管理员角色 |
| 404 | 端点未找到 | 验证REST API是否启用 |
| 400 | 数据无效 | 检查分类/标签ID是否存在 |
| 500 | 服务器错误 | 重试或检查WordPress错误日志 |
最佳实践
- 始终先预览- 创建为草稿,验证后再发布
- 使用应用程序密码- 切勿使用常规WordPress密码
- 选择适当的分类- 有助于网站组织和SEO
- 生成相关标签- 提高谷歌可发现性
- 验证Gutenberg区块- 确保区块结构正确
- 保持摘要不超过160个字符- 最佳搜索摘要长度
- 使用描述性别名- 在URL中包含主要关键词
文章底部电脑广告
手机广告位-内容正文底部


微信扫一扫,打赏作者吧~