A simple package to post HTML content with images to WordPress
Project description
WordPress Poster Package
A simple Python package to post HTML content with images to WordPress via the REST API.
Features
- ✅ Upload images from URLs or local file paths to WordPress media library
- ✅ Replace image paths/URLs in HTML with WordPress media URLs automatically
- ✅ Post HTML content to WordPress
- ✅ Automatic title extraction from HTML
- ✅ Comprehensive error handling
- ✅ Supports both absolute and relative file paths
Installation
From Source
pip install -e .
Build and Install
python setup.py sdist bdist_wheel
pip install dist/wordpress_poster-1.0.0.tar.gz
Usage
from wordpress_poster import post_to_wordpress
# Post with images
result = post_to_wordpress(
wordpress_url="https://yoursite.com",
wordpress_username="your_username",
wordpress_password="your_app_password",
html_content="<h1>My Post</h1><p>Content here</p>",
image_links=[
"https://example.com/image1.jpg",
"https://example.com/image2.png"
],
title="My Blog Post", # Optional, will extract from HTML if not provided
status="publish" # Optional, default is "publish"
)
post_id, post_link, upload_info = result
if post_id:
print(f"Post created! ID: {post_id}, Link: {post_link}")
print(f"Uploaded images: {upload_info['uploaded_images']}")
else:
print("Failed to create post")
Parameters
wordpress_url(str, required): Your WordPress site URL (e.g., "https://yoursite.com")wordpress_username(str, required): WordPress usernamewordpress_password(str, required): WordPress application password (not regular password)html_content(str, required): HTML content to post (may contain image paths like<img src="/content/image.png" />)image_links(list, optional): List of image URLs (http://, https://) or local file paths (e.g., "/content/image.png"). Paths should match what appears inhtml_content.title(str, optional): Post title (will extract from<h1>tag if not provided)status(str, optional): Post status (default: "publish")
Returns
Returns a tuple: (post_id, post_link, upload_info)
post_id: WordPress post ID (None if failed)post_link: URL to the published post (None if failed)upload_info: Dictionary containing:uploaded_images: Dict mapping original image paths/URLs to WordPress media URLsfailed_images: List of image paths/URLs that failed to upload
WordPress Setup
- Enable REST API in WordPress (usually enabled by default)
- Create an Application Password:
- Go to Users → Your Profile
- Scroll to "Application Passwords"
- Create a new application password
- Use this password (not your regular WordPress password)
Notes
- The function automatically sets
WP_USE_COOKIE_AUTH="false"as an environment variable - Images are processed one by one (downloaded from URLs or read from local paths) and uploaded to WordPress
- Image paths/URLs in HTML are automatically replaced with WordPress media URLs
- Supports both absolute and relative file paths (e.g., "/content/image.png" or "./images/image.png")
- The HTML content is wrapped in
<!-- wp:html -->blocks to preserve formatting - For local file paths, the package will search for files relative to the current working directory
Requirements
- Python 3.7+
- requests >= 2.31.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file apex_wordpress_poster-0.1.2.tar.gz.
File metadata
- Download URL: apex_wordpress_poster-0.1.2.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d7ff33f1096296b28ad46b6b06139dbb36f6c06bd02ce5bd2ecee4abbe83562
|
|
| MD5 |
9f141661e100cd6753fc3c1b047cd6c3
|
|
| BLAKE2b-256 |
2102c0e0c289139f69c67e7010ab94f8b70de8f9bfc42186ffca6ad4bae6c0c2
|
File details
Details for the file apex_wordpress_poster-0.1.2-py3-none-any.whl.
File metadata
- Download URL: apex_wordpress_poster-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c9d6f3248aa9854fb0f0eef9a046f3e4a9961f746c3a27c83bced0ee585fc1c
|
|
| MD5 |
901955df3a42ce46c8a542bec9ee9f7b
|
|
| BLAKE2b-256 |
1dc95aff5aa95720a33e39fed22cb9ac739331e953b9b2dc4d5d6539e4aa79cf
|