Created
October 13, 2024 23:43
-
-
Save reddgr/545d6a378d5fcaf9bca050014f0ce0d1 to your computer and use it in GitHub Desktop.
Creates Wordpress pages in bulk from HTML files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Path to the directory containing our HTML files | |
HTML_DIR="$HOME/wordpress/wp-content/uploads/grok" | |
# Loop through all HTML files in the directory | |
for html_file in "$HTML_DIR"/*.html; do | |
# Extract the file name without the extension | |
file_name=$(basename "$html_file" .html) | |
# Replace "-" with " " in the file name to form the title | |
title=$(echo "$file_name" | tr '-' ' ') | |
# Read the content of the HTML file | |
content=$(cat "$html_file") | |
# Create a new WordPress page with the HTML content using WP-CLI | |
wp post create --post_type=page --post_title="$title" --post_status=publish --post_content="$content" | |
echo "Published page: $title" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment