0

If my post title is : Hello <b>world</b>

When exporting the posts with built-in Tools/Export, html tags are removed. I don't want that.

I have 9K posts to export with valuable styling in all titles, so even if it is not the best practice, these tags need to be kept.

In what file is the xml generated ?
Or is there some kind of hook for this ?

Thank you.

6
  • 3
    You're not supposed to be able to have HTML tags in a title, the only reason you've been able to put them in is because as an administrator/super admin you're given the unfiltered_html capability, which lets you do dangerous things. Even if your XML file contained the tags in the header on export, there's no guarantee that they won't be stripped out on import, or that the theme on the other site will even support it
    – Tom J Nowell
    Feb 2 '21 at 11:29
  • @TomJNowell Sure. But i have 9K posts to export with valuable styling in all titles. I need to find a way. Thanx for the tip!
    – jDelforge
    Feb 2 '21 at 11:56
  • 1
    How are you exporting the data? are you using a plugin or you wrote some custom code? Feb 2 '21 at 12:13
  • @jDelforge also note that any inline styling or tags can play havoc with RSS, AMP, Google, FB, twitter, OEmbed previews, etc etc OG tags can mitigate some of this but it's still an issue. You're not supposed to have inline styling in titles. Are all your tags and styles the same as what's in your question? Were you using this to try and create sub-titles?
    – Tom J Nowell
    Feb 2 '21 at 12:18
  • @Buttered_Toast Post edited : I'm exporting with built-in Tools/Export. It is simple and complete for my needs... I just have a problem with the titles.
    – jDelforge
    Feb 2 '21 at 12:35
-1

In the file wp-admin/includes/export.php

Within the post loop, line 545, simply replace

$title = apply_filters( 'the_title_rss', $post->post_title );

with

$title = $post->post_title;
8
  • 1
    That alone is not enough, you will also need to wrap the title in a CDATA tag. On line 568 instead of <title><?php echo $title; ?></title> type <title><![CDATA[<?php echo $title; ?>]]></title>, this will "tell" parsers that this is not an xml tag Feb 2 '21 at 13:08
  • Ok thank you. It is working without the CDATA (only export/import on another wp), but i take note of it.
    – jDelforge
    Feb 2 '21 at 13:13
  • This is extreme bad practice, you must never modify files in wp-admin or wp-includes
    – Tom J Nowell
    Feb 2 '21 at 13:37
  • 1
    You are correct that this should not be a permanent "fix" and that you should never edit core wordpress files directly, but if its for a single time use and the code is reverted back to the original there is nothing wrong about it. On occasion you will encounter a problem that will require you to edit core file/s, like OPs problem, just make sure to remove all your changes after. Feb 2 '21 at 13:46
  • @TomJNowell It fixes my problem. I export the posts, then i just discard my change on the repo.
    – jDelforge
    Feb 2 '21 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.