You have a WordPress site with a few hundred posts, a set of pages, categories, tags and an uploads folder full of images. You want all of it inside a Laravel app. How do you import WordPress to Laravel without losing content or links?
Here is the quick answer. There are two good ways to get the data out of WordPress: the WXR export file from Tools, Export, or the WordPress REST API. WXR is best for a one-time move. The REST API is best when the old site stays live during the build and you need to sync more than once. Either way, the import itself is a small Laravel command that maps posts, terms, media and SEO fields onto your own tables, and it should be safe to run twice.
A quick disclosure. We build Lara Dashboard, an MIT Laravel CMS, so the examples map onto our schema. Lara Dashboard core does not ship a one-click WordPress importer as of November 2026 (v1.5.0, Laravel 13, PHP 8.3+). This guide shows how to write one. The WordPress side applies to any Laravel app.
Plan the import before you write any code
Our WordPress to Laravel migration checklist covers the whole project: content, SEO, auth and media. This post zooms in on one step of it, moving the content. Before you start, decide three things.
What moves. Usually posts, pages, categories, tags, featured images, inline images and SEO titles and descriptions. Comments, form entries and plugin tables are separate jobs. Our 20-plugin map lists which plugins store their own data.
What stays the same. Keep slugs and publish dates exactly as they are. Changing them creates redirect work.
How often you run it. If you import once and switch DNS the same week, use WXR. If editors keep writing on WordPress for months while you build, use the REST API and run the import again before launch.
WXR export is the simplest path for a one-time move
In the WordPress admin, go to Tools, Export, choose All content, and download the file. It is an XML file in the WordPress eXtended RSS format, usually called WXR. It holds posts, pages, attachments, categories, tags, authors and post meta in one place. See our 15 WordPress concepts and their Laravel equivalents.
Each
<item> in the file is one post, page or attachment. The fields you need sit in a few XML namespaces. The body is in content:encoded and the excerpt in excerpt:encoded. The wp:post_type, wp:status, wp:post_name (the slug), wp:post_date_gmt and wp:post_parent fields hold the rest. Categories and tags appear as <category domain="category" nicename="..."> and domain="post_tag".Attachments are items too. Their file URL is in
wp:attachment_url. A post's featured image is a post meta row with the key _thumbnail_id, which points at the attachment's wp:post_id. If the site used Yoast SEO, the title and description are post meta rows with the keys _yoast_wpseo_title and _yoast_wpseo_metadesc.Parse the file with PHP's
SimpleXMLElement or XMLReader. Use XMLReader for large exports, because it streams the file instead of loading it all into memory. Two warnings. The WXR file does not contain the image files, only their URLs, so the old site must stay reachable while you download them. And the body still holds shortcodes such as [gallery] or [caption], which you need to convert or strip.The REST API is better when the old site stays live
WordPress exposes
/wp-json/wp/v2/posts, /wp-json/wp/v2/pages, /wp-json/wp/v2/categories, /wp-json/wp/v2/tags and /wp-json/wp/v2/media, unless a plugin has turned the API off.Paginate properly. The WordPress pagination docs cap
per_page at 100, and the default is 10. Read the X-WP-TotalPages header on the first response and loop with page=2, page=3 and so on. The X-WP-Total header gives the item count, which is useful for a final check.Embed what you need. Add
_embed to a posts request and the response includes the featured media and terms, which saves many extra calls. Without it, you get IDs in featured_media, categories and tags, and you look them up yourself.Use rendered content, on purpose. Public requests return
content.rendered, which is the HTML after WordPress has run its filters. That means shortcodes are already expanded, which is often what you want. It also means some plugin markup comes along, so plan a cleanup pass.Authenticate for drafts. Public requests return published content only. To import drafts, private posts and scheduled posts, create an Application Password for an editor account in the WordPress user profile and send it with HTTP Basic auth. See the WordPress REST API authentication docs.
Map WordPress fields onto your Laravel schema
Here is how WordPress fields map onto Lara Dashboard's tables. Your own Laravel models will have similar columns.
| WordPress | Lara Dashboard | Notes |
|---|---|---|
| post_type post / page | posts.post_type post / page | Custom post types need register_post_type() in a module first |
| post_title, post_name | title, slug | Slug is unique across the whole posts table |
| post_content, post_excerpt | content, excerpt | Rewrite image URLs and shortcodes first |
| publish, draft, pending, private, future | published, draft, pending, private, scheduled | Status names differ for publish and future |
| post_date_gmt | published_at | Store in UTC |
| post_parent (pages) | parent_id | Import parents first, then children |
| post_author | user_id | Required; map authors or use one import user |
| category, post_tag | terms with taxonomy category or tag | Linked through term_relationships |
| _thumbnail_id | featured media collection | Uses spatie/laravel-medialibrary |
| Yoast title and description | post meta seo_title, seo_description | Set with setMeta() |
A few details catch people out. First,
user_id is a required foreign key. Lara Dashboard fills it from the logged-in user when a post is created, but an Artisan command has no logged-in user. Set it yourself. Second, the slug column is unique for all post types together. The same is true for term slugs across categories and tags. WordPress allows both kinds of clash, so check before you import. Third, WordPress uses publish and future, while Lara Dashboard uses published and scheduled.Write the importer as an idempotent Artisan command
Put the importer in a small module, so you can delete it after launch.
php artisan module:make WpImport --plain gives you a minimal structure. Our guide to building a Laravel module step by step walks through the layout. Then add a console command that takes the WXR path or the WordPress site URL as an argument.Make every step safe to run again. Use
Post::updateOrCreate(['slug' => $slug], [...]) for posts and Term::firstOrCreate(['slug' => $slug, 'taxonomy' => 'category'], [...]) for terms. Store the old WordPress ID too, for example with $post->setMeta('wp_id', $wpId). You will need it to link featured images and page parents, and to debug later.Run the steps in this order.
- Import categories and tags, then set each term's parent.
- Import pages and posts, parents before children.
- Sync each post's terms with the terms relation.
- Download media, attach featured images and rewrite image URLs in the body.
- Copy SEO titles and descriptions into post meta.
- Print counts and compare them with the WordPress totals.
Wrap each post in a transaction and log failures instead of stopping the run. Add a
--dry-run option that validates without writing, and run it first.Media is the slow part, so treat it as its own step
Lara Dashboard's Post model uses spatie/laravel-medialibrary (v11 in our composer.json) with a
featured collection that accepts JPEG, PNG, GIF and WebP. For each post with a featured image, call $post->addMediaFromUrl($url)->toMediaCollection('featured'). The library downloads the file and stores it on your configured disk.Inline images need one more pass. Find every
wp-content/uploads URL in the body, download the file into the media library, and replace the old URL with the new one. Keep a map from old URL to new URL, so an image used in ten posts is downloaded once.Skip the resized copies WordPress makes, such as
photo-300x200.jpg, and point those URLs at the original. Bring the alt text too: WXR holds it in the _wp_attachment_image_alt meta row, and the REST API returns it as alt_text.Keep URLs, SEO fields and redirects intact
WordPress post URLs often look like
/2024/05/my-post/ or /blog/my-post/. Your theme decides the new pattern. In Lara Dashboard, a theme module sets the public URL through the POST_FRONTEND_URL filter, and without one the fallback is /post/{slug}.If the pattern changes, you need 301 redirects for every old URL. Generate the list from the import itself: for each post, write the old permalink and the new URL to a CSV. Lara Dashboard core has no redirect manager as of v1.5.0, so load that CSV into a small redirects table with a middleware, or use
Route::permanentRedirect() for a short list. Our guide on rebuilding a WordPress site in Laravel without losing rankings covers sitemaps, canonical tags and Search Console on launch day.For SEO meta, copy the Yoast or Rank Math title and description into
seo_title and seo_description with setMeta(). Lara Dashboard also has meta keys for the canonical URL, noindex and Open Graph fields, so carry those over if the old site used them.For a small site, an AI agent over MCP can do the import
If you only have 20 or 30 posts, a command may be more work than the job. Lara Dashboard's MCP server has tools to create posts, upload media, attach a featured image, and assign categories and tags. You can connect Claude or another MCP client, paste a batch of WordPress content, and let it create drafts that a person reviews. Our plain-English guide to MCP servers for a CMS explains how the tools and permissions work.
Be clear about the limits. The MCP create-post tool converts HTML into LaraBuilder blocks, so check the output on a few posts first. For anything over a few dozen posts, write the command.
Trade-offs: when not to write your own importer
A custom import is the right call for most moves, but not all of them.
- The site lives in a page builder that stores layout in its own format. The import brings the text, not the layout, so plan to rebuild those pages by hand.
- The real value is in plugin data, such as a store, a course system or membership records. That is a data migration, not a content import.
- The site is multilingual with WPML or Polylang. Translation links need their own mapping, and core Lara Dashboard translates the admin, not front-end content.
- You need a one-click importer for non-technical clients. Core does not have one today.
Self-check before you switch DNS
- The post, page, category and tag counts match the WordPress totals.
- Every slug matches the old one, and slug clashes between posts and pages are resolved.
- Publish dates and statuses are correct, including drafts and scheduled posts.
- Featured images show on list pages, and no body still points at wp-content/uploads.
- No raw shortcodes are left in the content.
- SEO titles and descriptions are present on your top 20 pages.
- Every old URL returns a 301 to the new one, or loads directly.
- The import runs twice without creating duplicates.
- The Application Password on the old site is deleted.
Verdict
Importing WordPress into Laravel is not hard, but it is detailed. Use WXR for a one-time move and the REST API when the old site stays live. Write one idempotent command, keep slugs and dates, treat media as its own step, and generate redirects from the import. Lara Dashboard gives you a posts table, terms, post meta, SEO fields and a media library that WordPress content maps onto cleanly, so the importer is one command, not a rewrite. If that sounds like your next migration, try Lara Dashboard and run the import against a fresh install first.
FAQ
Can I import a WordPress XML export into Laravel?
Yes. The WXR file from Tools, Export is plain XML. Parse it with XMLReader or SimpleXML, then create your posts, terms and media from each item.
Does Lara Dashboard have a WordPress importer?
Not in core as of v1.5.0. Its schema maps closely to WordPress: posts with types, statuses and parents, category and tag terms, post meta, SEO meta and a media library. That makes a custom import simple to write.
How do I get more than 100 posts from the WordPress REST API?
You can't in one request, because per_page is capped at 100. Read the X-WP-TotalPages header and request each page in turn until you reach the last one.
Will images move automatically?
No. Both WXR and the REST API give you image URLs, not files. Download each file into your media library while the old site is still online, and rewrite the URLs in the post body.
How do I keep my Google rankings after the import?
Keep slugs the same, copy SEO titles and descriptions, and add a 301 redirect for every URL whose pattern changes.
Can I import drafts and private posts?
With WXR, yes, they are in the export. With the REST API, you need to authenticate, for example with an Application Password for an editor account.