You are currently viewing Automate WordPress Posting with Python

Automate WordPress Posting with Python

Automate WordPress Posting with Python – Step-by-Step Guide


Want to save time? Learn how to automate WordPress posting with Python using REST API, app passwords, and Python scripts to publish content automatically.


Automate WordPress Posting with Python – Step-by-Step Guide

Do you manage a WordPress blog and feel tired of posting manually every time? Whether you’re working with AI-generated content or managing bulk blog schedules, you’ll love this automation trick.

In this article, I’ll show you how to automate WordPress posting with Python using the official REST API. This method is perfect for bloggers, developers, or content managers who want to simplify and streamline content publishing.


πŸ”₯ Why Automate WordPress Blog Posts?

Let’s be honest β€” logging in, pasting content, setting the title, categories, tags, featured image, and hitting “publish” every single time… it adds up. Especially when:

  • You use ChatGPT or Notion AI to generate articles

  • You post daily/weekly in bulk

  • You want to publish remotely or with a single click

  • You’re setting up a content system for your team

Here’s what you gain with automation:

βœ… Save time
βœ… Boost productivity
βœ… Ensure consistency
βœ… Enable integrations with AI, Google Sheets, or CSV inputs
βœ… Run your content pipeline like a pro!


🧰 What You Need to Automate WordPress with Python

Before jumping into code, here’s what you’ll need:

  • βœ… A self-hosted WordPress site

  • βœ… WordPress REST API (enabled by default in latest versions)

  • βœ… A WordPress username + application password

  • βœ… Python 3 (installed locally or on server)

  • βœ… Python requests library


πŸ” Step 1: Create a WordPress Application Password

  1. Log in to your WordPress admin

  2. Go to Users > Profile

  3. Scroll to Application Passwords

  4. Enter a name like PythonPoster and click Generate Password

  5. Copy the password (you won’t see it again!)

πŸ›‘ This password is used for secure authentication between Python and your WordPress site.


πŸ§ͺ Step 2: Install Python Requests Library

If you don’t already have it installed:

bash
pip install requests

πŸ’» Step 3: Python Script to Post to WordPress

Here’s a simple Python script to post a blog:

python
import requests
from requests.auth import HTTPBasicAuth

wp_url = "https://yourdomain.com/wp-json/wp/v2/posts"
username = "your_wp_username"
app_password = "your_app_password_here"

post = {
'title': 'This is an Automated Post from Python',
'status': 'publish',
'content': 'This blog post was published using Python and the WordPress REST API.',
'categories': [1], # Replace with your actual category ID
'tags': [3, 5] # Replace with tag IDs if needed
}

response = requests.post(wp_url, auth=HTTPBasicAuth(username, app_password), json=post)

print("Status Code:", response.status_code)
print("Post Link:", response.json().get("link"))


πŸ“Έ Image with Alt Text

Insert an image related to automation or Python with:

html
<img src="automate-posting.webp" alt="automate wordpress posting with python" />

πŸ”— External DoFollow Link

Learn more about the WordPress REST API here to understand all the available endpoints.

πŸ–ΌοΈ Add Featured Image via Python

Want to upload a featured image automatically? Yes da, we can do that with another POST request using the WordPress Media API.

Automate WordPress Posting with Python


βœ… Step 4: Upload and Attach Featured Image (Python Code)

python
import requests
from requests.auth import HTTPBasicAuth

media_url = "https://yourdomain.com/wp-json/wp/v2/media"
image_path = "your_image.jpg"

headers = {
'Content-Disposition': 'attachment; filename="your_image.jpg"',
'Content-Type': 'image/jpeg'
}

with open(image_path, 'rb') as img:
media_upload = requests.post(
media_url,
auth=HTTPBasicAuth("your_wp_username", "your_app_password"),
headers=headers,
data=img
)

media_id = media_upload.json().get('id')
print("Image ID:", media_id)

Now use that media_id in your post like this:

python
post = {
'title': 'Post with Image',
'content': 'This post has a featured image.',
'status': 'publish',
'featured_media': media_id
}

πŸ“ Automate Posting from CSV or JSON

If you have multiple articles, use this logic to loop over them:

python
import csv

with open("posts.csv", newline='') as file:
reader = csv.DictReader(file)
for row in reader:
post = {
'title': row['title'],
'content': row['content'],
'status': 'publish',
'categories': [int(row['category_id'])],
'tags': [int(tag) for tag in row['tag_ids'].split(",")]
}

response = requests.post(
wp_url,
auth=HTTPBasicAuth(username, app_password),
json=post
)

print("Posted:", response.status_code, row['title'])

🟒 Perfect for posting ChatGPT-generated content automatically!


⏰ Schedule Posts in Advance

To schedule instead of publishing now:

python
from datetime import datetime, timedelta

scheduled_time = (datetime.utcnow() + timedelta(hours=3)).isoformat()
post['status'] = 'future'
post['date_gmt'] = scheduled_time

This will schedule your post 3 hours later from current UTC time.

Automate WordPress Posting with Python


πŸ“Ž Add Internal Links (from Bloggersurf.com)

You can add internal links directly in the content:

python
post['content'] = (
'Check out <a href="https://bloggersurf.com/ai-tools">our favorite AI tools</a> '
'or learn <a href="https://bloggersurf.com/schedule-social-media-posts-free">how to schedule social posts for free</a>.'
)

πŸ“Œ Frequently Asked Questions (FAQ)

❓ Can I automate bulk blog posts with Python?

Yes, you can loop over a CSV, Google Sheet (via API)(), or even scrape data from a source and post automatically using the same logic.


❓ Is this method safe?

Yes. WordPress application passwords are secure and give limited access β€” better than using your main password.(Automate WordPress Posting with Python)


❓ Will this work for images, tags, and SEO?

Yes. You can upload images, assign tags/categories, and even set meta fields using plugins like Yoast or Rank Math API hooks.(Automate WordPress Posting with Python)

More about Automation

This Post Has 15 Comments

  1. Alcomix

    НуТСн Π±Ρ‹Π» алкоголь срочно, Π½ΠΎ всС Ρ‚ΠΎΡ‡ΠΊΠΈ ΡƒΠΆΠ΅ Π·Π°ΠΊΡ€Ρ‹Ρ‚Ρ‹. Π’Π²Ρ‘Π» Π² поискС ЯндСкса «круглосуточная доставка алкоголя» β€” ΠΈ сразу доставка алкоголя круглосуточно. ΠŸΡ€ΠΈΠ²Π΅Π·Π»ΠΈ всё Π±ΡƒΠΊΠ²Π°Π»ΡŒΠ½ΠΎ Ρ‡Π΅Ρ€Π΅Π· час. Π’Π΅ΠΏΠ΅Ρ€ΡŒ знаю, Π³Π΄Π΅ Π±Ρ€Π°Ρ‚ΡŒ, Π΄Π°ΠΆΠ΅ Π² ΠΏΠΎΠ»Π½ΠΎΡ‡ΡŒ.

  2. xlkaiuwoi

    Top Link Providers for Gambling Websites
    BEST LINKS FOR GAMBLING! suncitywestdental.com/ BEST LINKS FOR GAMBLING! TELEGRAM @the_telegraf
    BEST LINKS FOR GAMBLING!
    BEST LINKS FOR GAMBLING! http://www.fortworthmillerdental.com BEST LINKS FOR GAMBLING! TELEGRAM @happygrannypies
    BEST LINKS FOR GAMBLING! http://www.huroncoastdental.com BEST LINKS FOR GAMBLING! TELEGRAM @happygrannypies
    BEST LINKS FOR GAMBLING!
    BEST LINKS FOR GAMBLING! http://www.danapricedental.com BEST LINKS FOR GAMBLING! TELEGRAM @happygrannypies

  3. РСшила ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ Π²Π΅Ρ‡Π΅Ρ€ особСнным, Π½ΠΎ Π½Π΅ Π·Π½Π°Π»Π°, Π³Π΄Π΅ Π²Π·ΡΡ‚ΡŒ Π½ΡƒΠΆΠ½Ρ‹ΠΉ Π½Π°ΠΏΠΈΡ‚ΠΎΠΊ. Пошла Π² Google ΠΈ Π½Π°Π±Ρ€Π°Π»Π° Β«ΠΊΠ°ΠΊ Π·Π°ΠΊΠ°Π·Π°Ρ‚ΡŒ алкоголь Ρ‡Π΅Ρ€Π΅Π· ΠΈΠ½Ρ‚Π΅Ρ€Π½Π΅Ρ‚ с доставкой». ΠŸΠ΅Ρ€Π²Ρ‹ΠΉ ΠΆΠ΅ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ β€” ΠΊΠ°ΠΊ Π·Π°ΠΊΠ°Π·Π°Ρ‚ΡŒ алкоголь Ρ‡Π΅Ρ€Π΅Π· ΠΈΠ½Ρ‚Π΅Ρ€Π½Π΅Ρ‚ с доставкой. ΠžΡ„ΠΎΡ€ΠΌΠΈΠ»Π° β€” ΠΈ ΠΎΡΡ‚Π°Π»Π°ΡΡŒ Π² восторгС!

  4. svt-stroy.ru – ВсС ΠΎ стройкС ΠΈ Ρ€Π΅ΠΌΠΎΠ½Ρ‚Π΅.
    Π Π°Π·Π±ΠΈΡ€Π°Π΅ΠΌ ΠΏΠΎΠ΄Ρ€ΠΎΠ±Π½ΠΎ – Π‘ΠΊΠ°ΠΆΠΈΡ‚Π΅ Π²ΠΎΠ΄Π΅ «НЕВ»: гидроизоляция Π΄ΠΎΠΌΠ° ΠΎΡ‚ Ρ„ΡƒΠ½Π΄Π°ΠΌΠ΅Π½Ρ‚Π° Π΄ΠΎ ΠΊΡƒΡ…Π½ΠΈ Π² нашСм ΡΡ‚Ρ€ΠΎΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΠΌ Π±Π»ΠΎΠ³Π΅.
    Π‘ΠΎΠ²Π΅Ρ‚Ρ‹ ΠΎΠΏΡ‹Ρ‚Π½Ρ‹Ρ… спСциалистов, Π΄ΠΈΠ·Π°ΠΉΠ½Π΅Ρ€ΠΎΠ² ΠΈ ΠΈΠ½ΠΆΠ΅Π½Π΅Ρ€ΠΎΠ²! Π Π΅ΠΌΠΎΠ½Ρ‚ΠΈΡ€ΡƒΠΉΡ‚Π΅ свой Π·Π°Π³ΠΎΡ€ΠΎΠ΄Π½Ρ‹ΠΉ Π΄ΠΎΠΌ с ΡƒΠΌΠΎΠΌ!

  5. НуТно Π±Ρ‹Π»ΠΎ быстро Π·Π°ΠΊΡƒΠΏΠΈΡ‚ΡŒΡΡ ΠΏΠ΅Ρ€Π΅Π΄ ΠΏΡ€ΠΈΡ…ΠΎΠ΄ΠΎΠΌ гостСй. Π£Π²ΠΈΠ΄Π΅Π» Ρ€Π΅ΠΊΠ»Π°ΠΌΡƒ алкоголь Π΄ΠΎΠΌΠΎΠΉ доставка москва Π² YouTube-Ρ€ΠΎΠ»ΠΈΠΊΠ΅ ΠΏΡ€ΠΎ Π±Ρ‹Ρ‚ΠΎΠ²Ρ‹Π΅ Π»Π°ΠΉΡ„Ρ…Π°ΠΊΠΈ . НС Π΄ΡƒΠΌΠ°Π», Ρ‡Ρ‚ΠΎ Ρ‚Π°ΠΊ ΡƒΠ΄ΠΎΠ±Π½ΠΎ β€” Π²Ρ‹Π±Ρ€Π°Π», ΠΎΠΏΠ»Π°Ρ‚ΠΈΠ», ΠΏΠΎΠ»ΡƒΡ‡ΠΈΠ». Всё Π±ΡƒΠΊΠ²Π°Π»ΡŒΠ½ΠΎ Π·Π° ΠΏΠ°Ρ€Ρƒ часов. ΠžΡ‚Π»ΠΈΡ‡Π½ΠΎΠ΅ Ρ€Π΅ΡˆΠ΅Π½ΠΈΠ΅ для спонтанных Π²Π΅Ρ‡Π΅Ρ€ΠΈΠ½ΠΎΠΊ.

  6. YandGlype

    ΠšΡƒΠΏΠΈΡ‚ΡŒ Π₯Π°Π²Π°Π» – Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Ρƒ нас Π²Ρ‹ Π½Π°ΠΉΠ΄Π΅Ρ‚Π΅ Ρ€Π°Π·Π½Ρ‹Π΅ ΠΊΠΎΠΌΠΏΠ»Π΅ΠΊΡ‚Π°Ρ†ΠΈΠΈ. БыстрСй всСго ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ Π·Π°ΠΊΠ°Π· Π½Π° Π½ΠΎΠ²Ρ‹ΠΉ Ρ…Π°Π²Π΅ΠΉΠ» 2025 ΠΌΠΎΠΆΠ½ΠΎ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ Ρƒ нас!
    haval новая модСль
    Π½ΠΎΠ²Ρ‹ΠΉ Ρ…Π°Π²Π΅ΠΉΠ» 2025 – https://www.havalmsk1.ru/

  7. Π₯ΠΎΡ‚ΠΈΡ‚Π΅ ΡƒΠ·Π½Π°Ρ‚ΡŒ, сколько стоит высокоточноС Π»Π΅Ρ‡Π΅Π½ΠΈΠ΅? Π£Ρ‚ΠΎΡ‡Π½ΠΈΡ‚Π΅ Π»Π΅Ρ‡Π΅Π½ΠΈΠ΅ Π·ΡƒΠ±ΠΎΠ² ΠΏΠΎΠ΄ микроскопом ΡΡ‚ΠΎΠΈΠΌΠΎΡΡ‚ΡŒ. Π­Ρ‚Π° тСхнология ΠΏΠΎΠΌΠΎΠ³Π°Π΅Ρ‚ спасти Π΄Π°ΠΆΠ΅ Π±Π΅Π·Π½Π°Π΄Ρ‘ΠΆΠ½Ρ‹Π΅ Π·ΡƒΠ±Ρ‹. И Π΄Π°, Ρ†Π΅Π½Π° вас приятно ΡƒΠ΄ΠΈΠ²ΠΈΡ‚. ΠŸΠΎΠ΄Ρ€ΠΎΠ±Π½ΠΎΡΡ‚ΠΈ Π½Π° сайтС Π΄ΠΎΠ±Ρ€Ρ‹Π΅Π²Ρ€Π°Ρ‡ΠΈ18.Ρ€Ρ„ β€” Π·Π°ΠΏΠΈΡΡ‹Π²Π°ΠΉΡ‚Π΅ΡΡŒ Π½Π° ΠΊΠΎΠ½ΡΡƒΠ»ΡŒΡ‚Π°Ρ†ΠΈΡŽ.

Leave a Reply