--- 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 '

Import Docx

'; if $error is set output '

'.esc_html($error).'

'; render a form method=POST enctype=multipart/form-data; call wp_nonce_field('wp_docx_import'); output a p with a label 'Word document (.docx)' and a file input name=docx_file accept=.docx required; output a p with a submit button class=button-primary value='Create Draft'; close form and wrap div. No stylesheet, no script. ``` ## Reading word/document.xml with core PHP A .docx file is a ZIP archive, and the whole body of the document is in `word/document.xml`. `ZipArchive` opens the archive and `DOMDocument` with `DOMXPath` parses the XML: no library installs and no Composer, just PHP every WordPress host already has. Google Docs exports via File > Download > Microsoft Word (.docx) use the same format and import the same way. The built-in Heading1, Heading2 and Heading3 styles become h1, h2 and h3; paragraphs become `p`; bold runs become `strong` and italic runs `em`. The first h1 becomes the post title, or the filename if there is none. The draft is created with you as its author, and you land on its edit screen as soon as it is saved. ## Images, tables and Elementor layouts Images embedded in a Word file sit in a separate `word/media/` folder in the ZIP, and only the document body is read, so they do not come across. Upload them through the Media Library and insert them into the draft. Tables are skipped. Word's table XML is shaped differently from prose, and converting it reliably to HTML is enough extra logic to be its own step. Elementor keeps its layout in post meta, not `post_content`. The draft holds standard HTML, which is what Gutenberg and the classic editor use, so Elementor will show the text but none of its column or widget structure. On an all-Elementor site, treat the draft as the copy and rebuild the layout. ## When pasting is still quicker One or two posts a month: the plugin adds a step pasting does not, and Gutenberg handles most Word formatting with no setup. Documents built on custom heading styles, as agency and corporate templates often are, rather than the built-in Heading1 to Heading3, come through as plain paragraphs and lose their structure. Run a test file before trusting it with a whole batch. It takes one file per upload, with no folder watching or scheduled pulls from a shared drive. A follow-up message can accept several files in one submission with a summary of the drafts created, convert tables in their original position, or add your custom style names to the heading mapping. ## Questions ### Does it work with password-protected Word files? No. A password encrypts the ZIP contents, so PHP cannot read `document.xml` and the import fails. Remove the password in Word under File > Info > Protect Document, save, and upload again. --- Source: https://steem.dev/blog/wordpress-import-word-doc-plugin Build this plugin: https://steem.dev/app