If you’re looking to streamline your WordPress content creation process, ChatGPT can be a powerful ally. In this guide, I’ll walk you through how to automatically generate WordPress posts using the WordPress REST API and ChatGPT—without the need for an OpenAI API key or any additional plugins.
Prerequisites
1. WordPress Installation: Make sure you have a WordPress website set up and running.
2. Basic Knowledge of WordPress REST API: Familiarize yourself with the WordPress REST API endpoints and how they work.
Step 1: Set Up Your WordPress Environment
Ensure that your WordPress installation is up-to-date and functioning properly. You’ll need access to the WordPress dashboard and the ability to create and manage posts.
Step 2: Retrieve Your WordPress REST API Endpoint
1. Log in to your WordPress dashboard.
2. Navigate to the “Settings” menu and select “Permalinks.”
3. Note down the base URL for your WordPress site (e.g., `https://yourdomain.com`).
Step 3: Retrieve Your Application Password
To authenticate with the WordPress REST API, you’ll need an application password. Follow these steps to create one:
- In your WordPress dashboard, go to “Users” and select your user profile.
- Scroll down to the “Application Passwords” section.
- Click “Add New.”
- Enter a name for your application (e.g., “ChatGPT”).
- Click “Generate Password.”
- Note down the generated password.
Step 4: Retrieve the Generated Content from ChatGPT
1. Visit the ChatGPT website.
2. Enter a prompt related to your desired post topic (e.g., “Write an article about AI in marketing”).
3. ChatGPT will generate content based on your prompt.
Step 5: Transform the generated article into WordPress Raw JSON content format
Use the following prompt to get the necessary JSON data that will be the request body of the WordPress REST API call.
Here is an example showing the exact same article using Markdown-formatted content vs. WordPress Raw JSON:
// start of Markdown formatted content
## Heading 2
Paragraph
### Heading 3
Paragraph
Some **strong bold** and *italic emphasis* text.
Bulleted list:
- Bulleted Item 1
- Bulleted Item 2
- Bulleted Item 3
Numbered list:
1. Numbered Item 1
2. Numbered Item 2
3. Numbered Item 3
// end of Markdown formatted content
WordPress Raw JSON:
```json
{
"status": "draft",
"title": {
"raw": "Article Title"
},
"excerpt": {
"raw": "(put the excerpt here)",
},
"content": {
"raw": "<!-- wp:heading -->\n<h2 class=\"wp-block-heading\">Heading 2</h2>\n<!-- /wp:heading -->\n\n<!-- wp:paragraph -->\n<p>Paragraph</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:heading {\"level\":3} -->\n<h3 class=\"wp-block-heading\">Heading 3</h3>\n<!-- /wp:heading -->\n\n<!-- wp:paragraph {\"placeholder\":\"Type / to choose a block, or press space to summon the AI Copilot\"} -->\n<p>Paragraph</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>Some <strong>strong bold</strong> and <em>italic emphasis</em> text.</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:paragraph {\"placeholder\":\"Type / to choose a block, or press space to summon the AI Copilot\"} -->\n<p>Bulleted list:</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:list -->\n<ul><!-- wp:list-item -->\n<li>Bulleted Item 1</li>\n<!-- /wp:list-item -->\n\n<!-- wp:list-item -->\n<li>Bulleted Item 2</li>\n<!-- /wp:list-item -->\n\n<!-- wp:list-item -->\n<li>Bulleted Item 3</li>\n<!-- /wp:list-item --></ul>\n<!-- /wp:list -->\n\n<!-- wp:paragraph {\"placeholder\":\"Type / to choose a block, or press space to summon the AI Copilot\"} -->\n<p>Numbered list:</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:list {\"ordered\":true} -->\n<ol><!-- wp:list-item -->\n<li>Numbered Item 1</li>\n<!-- /wp:list-item -->\n\n<!-- wp:list-item -->\n<li>Numbered Item 2</li>\n<!-- /wp:list-item -->\n\n<!-- wp:list-item -->\n<li>Numbered Item 3</li>\n<!-- /wp:list-item --></ol>\n<!-- /wp:list -->",
"block_version": 1
},
}
```
Based on that, step-by-step. First, generate an excerpt for the article that you will use for the next step. Then please transform that article you have generated before into WordPress Raw JSON. Output only the WordPress Raw JSON.
Copy and paste the JSON file generated file by ChatGPT into a file named article.json
on your computer.
Step 6: Use cURL to Create a New Post
Open your terminal or command prompt and run the following cURL command to create a new WordPress post:
curl -X POST -H "Content-Type: application/json" -d @article.json -u "yourusername:yourapplicationpassword" "https://yourdomain.com/wp-json/wp/v2/posts"
Replace yourusername and yourapplicationpassword with your WordPress username and application password you have retrieved above.
Now you should have a new post waiting for you on your WordPress dashboard. Congratulations!
Step 7: Edit and Tailor the Generated Article
- Log in to your WordPress dashboard.
- Navigate to “Posts” and select the newly created post.
- Click “Edit” to open the post in the WordPress editor.
- Review the content generated by ChatGPT.
- Make any necessary edits, add images, format text, and ensure it aligns with your brand voice.
- Optimize for SEO by adding relevant keywords and meta descriptions.
- Preview the post to see how it looks.
- Once satisfied, click “Update” to save your changes.
Now you’re ready to publish a customized, AI-assisted post on your WordPress site. Happy blogging! 🚀
Conclusion
Automating content creation for your WordPress site has never been easier. By combining the power of ChatGPT with the WordPress REST API, you can generate high-quality posts without the need for complex setups or additional plugins. Whether you’re a blogger, marketer, or business owner, this streamlined approach will save you time and effort.
Remember to review the generated content, add your personal touch, and optimize it for your audience. Now, go forth and let ChatGPT be your writing companion as you create engaging content for your WordPress website!
Frequently Asked Questions (FAQ)
- Is an OpenAI API key required for this process? No, you don’t need an OpenAI API key. We’re leveraging ChatGPT via the ChatGPT website, which doesn’t require an API key.
- Can I customize the generated content further? Absolutely! After retrieving content from ChatGPT, feel free to edit, format, and enhance it to match your brand voice and style.
- What if I want to include images or other media in my posts? While this guide focuses on text content, you can extend it by adding media elements using the WordPress REST API or other plugins.
- Are there any limitations to using the WordPress REST API? The REST API provides powerful capabilities, but be aware of security considerations. Always use authentication (such as application passwords) to protect your site.
- Can I automate other tasks with ChatGPT and WordPress? Absolutely! Explore other use cases, such as generating meta descriptions, creating category pages, or even automating social media posts.
Feel free to experiment, iterate, and make the most of this efficient content creation process. Happy writing! 🚀