Skip to main content

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 to WordPress media library
  • ✅ Replace image URLs in HTML with WordPress media URLs
  • ✅ Post HTML content to WordPress
  • ✅ Automatic title extraction from HTML
  • ✅ Comprehensive error handling

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 username
  • wordpress_password (str, required): WordPress application password (not regular password)
  • html_content (str, required): HTML content to post
  • image_links (list, optional): List of image URLs to download and upload
  • 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 URLs to WordPress media URLs
    • failed_images: List of image URLs that failed to upload

WordPress Setup

  1. Enable REST API in WordPress (usually enabled by default)
  2. 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 downloaded, uploaded one by one, and then replaced in the HTML content
  • The HTML content is wrapped in <!-- wp:html --> blocks to preserve formatting

Requirements

  • Python 3.7+
  • requests >= 2.31.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apex_wordpress_poster-0.1.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apex_wordpress_poster-0.1.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file apex_wordpress_poster-0.1.1.tar.gz.

File metadata

  • Download URL: apex_wordpress_poster-0.1.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for apex_wordpress_poster-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bbba1f14a60e60b166b702c2981dc1db9bb450d36adcb680272ddf73583cc3bb
MD5 544c07b74cceae6165d1d3c8d3894e02
BLAKE2b-256 fc615fa7149a19ff96bf779aef762f31ceb9b1d03deca1aa607fda6c80a9054c

See more details on using hashes here.

File details

Details for the file apex_wordpress_poster-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for apex_wordpress_poster-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bbf847bcbff955c90cb551ff8ffa09c2db3ebb83794e7d6d995a00532f40d6a7
MD5 567c499b03d6ba13902718e565542a55
BLAKE2b-256 070d8e257ef1485c3c05149308fa8e8459caf379dbfa39f98956fdca2e4f3758

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page