Skip to content
WordPress

How to Add an XML File to WordPress

· · 10 min read
Add an XML File to WordPress

XML shows up in WordPress in a handful of specific, unrelated contexts, and conflating them is where most confusion starts. Sometimes “adding an XML file” means uploading a sitemap for search engines. Sometimes it means importing a full content export from another WordPress site. Sometimes it’s a theme or plugin settings file. Each one has a different correct method, and using the wrong one wastes time or, worse, silently fails without telling you why.

This guide separates the three use cases and walks through the actual steps for each.

Why XML Specifically, and Not JSON or CSV

XML (Extensible Markup Language) was WordPress’s original choice for structured data exchange because it handles nested, hierarchical content well, a post with comments, each comment with its own metadata, categories, tags, and custom fields all nested inside a single post record. That structure maps naturally to XML’s tag-based format in a way that flat formats like CSV struggle with.

This is also why the built-in WordPress export/import tool still uses XML (technically a WordPress-flavored dialect called WXR, WordPress eXtended RSS) even though JSON has become more common elsewhere in modern web development. Sitemaps use XML for a similar reason: the sitemap protocol itself, maintained collaboratively by the major search engines, was standardized around XML from the start.

Use Case 1: Importing Content From an XML Export

This is the most common reason someone ends up needing to “add an XML file,” usually after exporting content from an old site, a client’s previous WordPress install, or a staging copy.

Start on the source site. Go to Tools, then Export, choose what to export (all content, or filter by post type, category, or author), and click Download Export File. This produces a .xml file, formatted as WXR, containing your posts, pages, comments, custom fields, categories, and tags, though notably not your media files themselves, only references to their URLs.

On the destination site, go to Tools, then Import. If the WordPress importer isn’t listed as already installed, click Install Now next to it, then Run Importer once it’s active. Click Choose File, select the .xml file from the source site, and click Upload file and import.

WordPress will likely prompt you to assign imported content to an existing author on the new site or create a new one matching the original author’s username. There’s also a checkbox to download and import file attachments, check this if you want the importer to attempt pulling in the actual media files referenced in the export, though this only works if the original site (and its media URLs) are still live and reachable at import time.

Click Submit, and WordPress works through the file, creating posts, pages, and terms as needed. Larger exports can take several minutes and occasionally hit PHP execution time limits on shared hosting, which shows up as the import appearing to hang or fail partway through.

If a large import fails or times out

Shared hosting environments often cap PHP execution time at 30 or 60 seconds, which isn’t enough for an import running into the thousands of posts. A few workarounds help: split the source export into smaller files by using the Export tool’s category or date filters to generate multiple smaller XML files instead of one giant one, or ask your host to temporarily raise the max_execution_time and memory_limit values for your account while you run the import.

Alternatively, WP All Import and similar plugins are built specifically for large or complex XML imports and handle chunking and timeouts more gracefully than the core importer, which was never designed with very large sites in mind.

Use Case 2: Uploading an XML Sitemap

A sitemap is a different kind of XML file entirely, a machine-readable list of your site’s URLs meant for search engines, not a content export meant for another WordPress install.

On a modern WordPress site running an SEO plugin, you almost never manually create or upload this file. Yoast SEO, Rank Math, and All in One SEO all generate and serve a sitemap automatically from your existing content, keeping it updated in real time as you publish, without any manual file handling required.

In Yoast, confirm this is enabled under SEO, then General, then Features, where the XML Sitemaps toggle should be on. The generated sitemap is then reachable at yourdomain.com/sitemap_index.xml.

Rank Math works almost identically: Rank Math, then Sitemap Settings, confirm the sitemap is enabled, and it’s served at the same yourdomain.com/sitemap_index.xml path by default.

If you genuinely need a manually created or hand-edited sitemap, for a highly custom setup an SEO plugin’s automatic generation doesn’t cover, you’d create the XML file following the sitemaps.org protocol and upload it via FTP to your site’s root directory, so it’s reachable at yourdomain.com/sitemap.xml. This is uncommon; most sites are better served by letting an SEO plugin handle it than maintaining a sitemap by hand, since manual sitemaps go stale the moment content changes and nobody remembers to update the file.

Submitting your sitemap to Google Search Console

Once your sitemap exists and is reachable, tell Google about it directly rather than waiting for organic discovery. Log into Google Search Console, select your property, go to Sitemaps under the Index section in the left sidebar, enter your sitemap URL (just the path after your domain, like sitemap_index.xml), and click Submit.

Google will process the sitemap and report back how many URLs were discovered versus how many were actually indexed, a gap worth watching over time since a large or growing gap often points to a deeper indexation issue worth investigating separately.

Use Case 3: Theme and Plugin Configuration Files

Some themes and plugins support exporting their settings as XML (though JSON has become more common for this specific use case in newer plugins) so you can back up a configuration or replicate it across multiple sites without manually re-entering every setting.

The exact process varies by plugin, but the general pattern is consistent: look for an Import/Export section in the plugin’s own settings screen, not the general WordPress Tools menu, since this kind of import is plugin-specific and doesn’t run through WordPress core’s importer. Upload the file where indicated, and the plugin parses its own configuration back into place.

Always test this kind of import on a staging site first if the plugin governs anything customer-facing, since a bad configuration import can silently overwrite working settings with values from a different site’s setup, and there’s rarely an easy undo once it’s applied.

Uploading XML Files Directly via FTP

For sitemap files, verification files some services require, or any other standalone XML that doesn’t go through an import tool, direct upload is often the simplest path.

Install an FTP client like FileZilla or Cyberduck, and connect using the credentials your host provides, usually available in your hosting control panel under something like FTP Accounts. Once connected, you’ll see your local files in one pane and your server’s files in the other.

Navigate to your site’s root directory, commonly public_html, htdocs, or www depending on the host, and drag the XML file from your local pane into the server pane. For a sitemap meant to be reachable at yourdomain.com/sitemap.xml, it needs to sit directly in that root directory, not nested in a subfolder.

Confirm the upload worked by visiting the file’s URL directly in a browser once it’s there.

Validating an XML File Before You Trust It

A malformed XML file, a missing closing tag, an unescaped special character, fails silently in ways that are hard to diagnose after the fact. Before importing or uploading anything significant, run it through a validator. The W3C offers a free online XML validator, and most code editors (VS Code, Sublime Text) flag basic syntax errors automatically as you view the file, which catches obvious problems before you’ve wasted time on an import that was doomed from the start.

This matters more for hand-edited or hand-generated XML than for files exported directly by WordPress or a plugin’s own export function, since those are almost always well-formed by construction.

Security Considerations When Uploading XML Files

An XML file itself can’t execute code the way a PHP file can, but that doesn’t make uploading one entirely risk-free. If your upload process runs through a vulnerable plugin’s file handler rather than WordPress’s own hardened Media or Import screens, a maliciously crafted XML file can occasionally be used in an XXE (XML External Entity) attack, where the file references an external entity that the parser then tries to resolve, potentially exposing server files or making unintended outbound requests.

This is a low-probability risk for the average site owner using core WordPress tools, since WordPress’s own XML parsing has been hardened against this class of attack for years. It becomes more relevant if you’re building custom functionality that parses uploaded XML directly with a raw PHP XML library rather than going through WordPress’s built-in importer. If a developer is writing that kind of custom code for your site, confirm they’re disabling external entity loading explicitly rather than relying on default library behavior.

For sitemap and content-export files coming from a source you trust, your own previous site, a client’s existing install, this isn’t something to lose sleep over. It matters more when accepting XML uploads from unknown third parties through a public-facing form.

A Full Walkthrough: Migrating Content Between Two Sites

Putting the pieces together end to end helps more than reading each step in isolation. Say you’re consolidating an old blog into a new, larger site.

First, on the old site, go to Tools, then Export, and choose “All content” unless you specifically want to exclude certain post types. Download the resulting XML file and open it briefly in a text editor just to confirm it’s not empty or truncated, a quick sanity check that costs nothing and catches a failed export before you’ve moved on to the next step.

Second, back up the destination site completely before touching anything. This is the step people skip when they’re in a hurry, and it’s the one that saves the most time if the import goes wrong.

Third, on the destination site, install and activate the WordPress Importer plugin if it isn’t already, then run it against your downloaded XML file through Tools, then Import. Check the box to download and import file attachments if the old site’s media is still live and reachable.

Fourth, once the import finishes, don’t assume it’s correct just because no error appeared. Spot-check a handful of imported posts directly: confirm the featured image came through, confirm categories and tags are attached correctly, and confirm the author is mapped to the right user account rather than defaulting to whoever ran the import.

Fifth, set up 301 redirects from the old site’s URLs to their new equivalents if the domain or URL structure is changing as part of this migration. The import itself doesn’t handle redirects; that’s a separate step using a redirect plugin or server-level rewrite rules, and skipping it is how migrated sites lose search rankings that took years to build.

Troubleshooting a Failed or Partial Import

If the import appears to run but posts are missing afterward, check the file size first against your server’s upload_max_filesize limit; a silent truncation at the size cap is more common than any error message, since many hosting environments simply stop accepting data past the limit without a clear warning in the WordPress interface.

If posts imported but images are broken, the file attachment checkbox was likely unchecked, or the source images were no longer reachable at the time of import. Re-running the import isn’t necessary just for missing media; a media-specific import tool or manually re-uploading and re-attaching the missing images to the correct posts is usually the more surgical fix.

If the import seems to hang indefinitely with no completion message, this is almost always a PHP execution timeout on a large file. Check your host’s error logs if you have access, or contact support and ask them to check the PHP error log for the timestamp when the import stalled; that log entry usually confirms whether it was a timeout, a memory limit, or something else entirely.

Frequently Asked Questions

Can I edit an exported WXR file before importing it somewhere else?
Yes, cautiously. It’s valid XML and can be opened in a text editor, but WordPress’s WXR format has specific structural requirements. Small text changes, fixing a typo in a post title, are generally safe; restructuring the file’s nesting is risky and can break the import entirely.

Does every WordPress site generate a sitemap automatically, even without a plugin?
As of WordPress 5.5, core itself generates a basic sitemap automatically at yourdomain.com/wp-sitemap.xml, even with no SEO plugin installed. It’s more limited than what Yoast or Rank Math produce, but it exists as a baseline.

Is there a file size limit for XML imports in WordPress?
Yes, tied to your server’s PHP upload_max_filesize and post_max_size settings, commonly somewhere between 2MB and 64MB depending on your host. Very large exports may need to be split into smaller files or imported through a dedicated plugin built for bigger datasets.

What’s the difference between sitemap.xml and sitemap_index.xml?
sitemap_index.xml is a sitemap of sitemaps, a common pattern on larger sites where posts, pages, categories, and other content types each get their own separate sitemap file, all referenced from one index file. sitemap.xml is typically used when a site is small enough not to need that split. Most current SEO plugins default to the index pattern regardless of site size.

Do I need to deactivate plugins before running an XML import?
Not generally, though deactivating plugins that hook into the post-save process (some SEO plugins recalculate metadata on every save, for instance) can meaningfully speed up a large import, since fewer processes run per imported post. Reactivate them once the import finishes.

Can I import an XML export from a non-WordPress platform directly?
No, not through the core WordPress importer, which expects the specific WXR format. Migrating from another platform, Blogger, Squarespace, a different CMS entirely, usually requires either that platform’s own WordPress-compatible export option if it has one, or a dedicated migration plugin built to translate that platform’s export format into something WordPress can actually read.

Getting XML Handling Right the First Time

The core skill here isn’t technical difficulty, none of these processes are especially hard, it’s correctly identifying which of the three use cases you’re actually dealing with before picking a method. A sitemap upload, a content import, and a plugin configuration restore all involve a file with the same .xml extension but require completely different tools and produce completely different results if you mix them up.