Exporting Wordpress posts and pages with paragraph tags included

By default, WordPress doesn’t include any <p> tags in the XML export. However, sometimes that would be the desired behavior – for example when migrating data to another system that does not automatically add paragraph tags.

The solution is actually quite simple. During export, run the exported content through same wpautop() function that’s used when displaying posts.

function codelight_content_export($content) {
 return wpautop($content);
}
add_filter('the_content_export', 'codelight_content_export', 999);

Add this to your functions.php and you’re set.

Note that you may want to do the same for your excerpts, in which case you should use the_excerpt_export filter.

Indrek Kõnnussaar

I'm a veteran Wordpress developer, context-driven tester, security enthusiast and the mastermind behind Codelight. I love building stuff that works and fixing stuff that doesn't.

Write me directly [email protected]

4 Responses to “Exporting WordPress posts and pages with paragraph tags included”

  1. James

    Thanks for your post, it was very helpful.

    Note: we had to put the add_filter(….) line in the wp-admin\includes\export.php file for it to work. We put it below the other add_filter at line 345.

    The function codelight_content_export() we placed at the end of the wp-includes\functions.php file and the export worked great!

    Thanks again!

    James

    Reply
  2. brnteka

    yep thanks for the post, placed it in functions.php and it worked as expected

    Reply
  3. pHghost

    Hello, I’m wondering, is there any way to do this with my blog on WordPress.com?

    As far as I am aware, you cannot run functions during expert there.

    Would be a ton of help!

    Reply
    • Indrek Kõnnussaar

      Sorry, no idea about wordpress.com, never used it.

      Reply

Leave a Reply

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×