--- title: Import Word documents to WordPress as drafts description: Pasting from Word works for a post or two. For a batch of .docx files, a small plugin turns each one into a WordPress draft. source: https://steem.dev/blog/wordpress-import-word-doc-plugin published: 2026-09-14 updated: 2026-10-31 alternative_to: Wordable site: Steem — AI WordPress plugin generator --- # Import Word documents to WordPress as drafts Pasting from Word into WordPress has got much better. Gutenberg strips most of the junk formatting and keeps headings, bold and paragraphs reasonably well. For one post you wrote yourself in Word, just paste it. It falls apart when the content is not yours to paste: a freelancer sending a batch of articles, an editor without WordPress access, a client handing over a folder of .docx files from a migration. Pasting twenty files is half a day's work and none of it is editing. This plugin adds one admin page: upload a .docx and get a WordPress draft with headings, paragraphs, bold and italic intact, opened in the editor ready for a featured image. No SFTP, no manual conversion and no third-party service. ## What one build covers - An admin menu page for uploading a .docx file - Headings (h1 to h3), paragraphs, bold, and italic extracted from word/document.xml using ZipArchive and DOMXPath - Post title taken from the first h1, or the filename if none is found - Draft created with wp_insert_post, author set to the uploading user - Redirect to the draft edit screen immediately after creation ## What it does not cover - Images embedded in the Word document; upload and insert them after the draft is created - Tables; add them with the follow-up prompt in the guide - Elementor layout; the draft contains standard HTML, not Elementor's meta format - Bulk or batch import; the plugin handles one file at a time without the follow-up - Password-protected .docx files; remove the password in Word before uploading ## The prompt ```text Build a WordPress plugin that imports .docx files as WordPress post drafts. Plugin Name: WP Docx Importer. Version: 1.0.0. Description: Create WordPress drafts from uploaded Word documents. Wrap all code in a function attached to plugins_loaded. Register a top-level admin menu page with add_menu_page: title 'Import Docx', menu title 'Import Docx', capability 'edit_posts', slug 'wp-docx-importer', callback 'wp_docx_importer_page', icon 'dashicons-upload'. In the page callback function: if REQUEST_METHOD is POST and wp_verify_nonce($_POST['_wpnonce'],'wp_docx_import') passes, process the upload: check that $_FILES['docx_file']['error'] === 0 and strtolower(pathinfo($_FILES['docx_file']['name'],PATHINFO_EXTENSION)) === 'docx', else set an $error string; if valid, open $_FILES['docx_file']['tmp_name'] with new ZipArchive, call open() with ZipArchive::RDONLY, read the 'word/document.xml' entry with getFromName(), close the zip; if open fails or the entry is false, set $error; otherwise parse the XML: create a new DOMDocument, call loadXML with LIBXML_NOERROR; create a DOMXPath, register namespace prefix 'w' as 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'; query '//w:p' for all paragraph nodes; for each paragraph node, query './/w:pPr/w:pStyle/@w:val' to get the style value; map 'Heading1' to 'h1', 'Heading2' to 'h2', 'Heading3' to 'h3', everything else to 'p'; for each run queried with './/w:r', check for './/w:rPr/w:b' to determine bold, './/w:rPr/w:i' for italic; concatenate text from all './/w:t' nodes; esc_html each fragment; wrap in strong if bold; wrap in em if italic; build the paragraph or heading HTML element and append to $html string; after all paragraphs, find the first h1 content for $title, fall back to sanitize_file_name(pathinfo($_FILES['docx_file']['name'],PATHINFO_FILENAME)) if none; call wp_insert_post with array('post_status'=>'draft','post_title'=>sanitize_text_field($title),'post_content'=>$html,'post_author'=>get_current_user_id()); if is_wp_error set $error else wp_redirect(admin_url('post.php?post='.$post_id.'&action=edit')) and exit. Render the page: echo '
'.esc_html($error).'