Skip to content

Convert exported WordPress XML data to a file based structure for Kirby

Notifications You must be signed in to change notification settings

splorp/wordpress-xml-to-kirby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WordPress XML to Kirby

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.

Requirements

Usage

  • Download this repository and extract the contents to a working directory
/wordpress-xml-to-kirby
composer require league/html-to-markdown
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

Include Featured Image Metadata

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.

Release Notes

20230122 — The “Clean Up In Aisle Five” Release

  • 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 to convert.php because that’s what it does

20200630 — The “Little Bump” Release

20200309 — The “Compositionally Challenged” Release

  • 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

20200308 — The “Word Up” Release

  • 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

About

Convert exported WordPress XML data to a file based structure for Kirby

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages