This script converts an XML file that has been exported in WordPress eXtended RSS (WXR) format to a flat file YAML structure for use with Kirby.
This version of the code is based on the original WPXML to Kirby script by Sally Lait with further modifications made by Stay Regular Media.
- PHP 7.2 or later
- Composer
- HTML To Markdown for PHP
- Download this repository and extract the contents to a working directory
/wordpress-xml-to-kirby
- Install the Composer dependency manager
- Require the HTML To Markdown for PHP library
composer require league/html-to-markdown
- Export the content of your WordPress site to an XML file
- To include featured image metadata in the XML file, see below
- Move to XML file to the working directory
- Create an export directory in the working directory with full permissions
mkdir /wordpress-xml-to-kirby/export`
chmod 777 /wordpress-xml-to-kirby/export
- Edit
convert.php
to add the name of the XML file and the export directory
$importfile = 'data.xml';
$exportdir = 'export/';
- Convert all the things!
php convert.php
To include the featured image metadata in the XML file, the WordPress core export.php
file must be modified.
- Open
wp-admin/includes/export.php
in your favourite text editor - Locate the following code block:
<wp:post_type><?php echo wxr_cdata( $post->post_type ); ?></wp:post_type>
<wp:post_password><?php echo wxr_cdata( $post->post_password ); ?></wp:post_password>
<wp:is_sticky><?php echo intval( $is_sticky ); ?></wp:is_sticky>
- Add the following code directly following the aforementioned code block:
<?php if ( has_post_thumbnail($post->ID) ) : ?>
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full') ?>
<wp:attachment_url><?php echo wxr_cdata( $image[0] ); ?></wp:attachment_url>
<?php endif; ?>
After this modification, the exported XML data will include links to any full sized featured images attached to pages or posts.
You can also modify the get_post_thumbnail_id
function to retrieve a link to another image size or include additional XML objects for multiple image sizes.
- Better handling of posts with empty
<title>
fields - Better handling of posts with
<title>
fields containing accented characters - Paragraph breaks are now maintained when processing
<content:encoded>
- Renamed several named array keys for clarity and consistency
- Tweaked formatting of exported files because pretty
- Renamed script from
index.php
toconvert.php
because that’s what it does
- Updated HTML to Markdown for PHP to version 4.10.0
- Updated HTML to Markdown for PHP to version 4.9.1
- Added checks for items that do not have associated
attachment_url
data - Fixed missing space preceding
Text:
content
- Initial release based on the WPXML to Kirby script
- Removed
index-events.php
for Modern Tribe’s The Event Calendar exports - Updated read me to describe this version of the script