WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I want to import the XML files with the aid of the WordPress Importer plugin, the blogs imported will lose all the slashes, i.e., "\", which are really contained in the XML files imported.

Since I have to use the LaTeX plug-in (Latex for WordPress plug-in), it becomes terrible.

In fact, maybe weeks ago, it worked well. There was no such problem at all. But from one day, I find that all changed. TT

Is there any one who know what's happening? Thank you very much!

share|improve this question
Are the slashes removed during import or are they imported and just not displayed? Does it happen if you use TwentyEleven and disable all other plugins? – toscho Apr 28 '12 at 14:53
Yes, they all disappeared during import. I tried, i.e., disabled all plug-ins, but the problem is still there. – shuiruge Apr 29 '12 at 5:03

The importer calls wp_insert_post() which runs stripslashes_deep() on the data. But the exporter doesn't run addslashes. Looks like a bug to me.

What you may try is to prepare the data during export.

Create a plugin with the following content and activate it before you run the export:

 * Plugin Name: Slash my export
 * Description: Adds extra back slashes to exported data.

add_filter( 'the_content_export', 'addslashes' );
add_filter( 'the_excerpt_export', 'addslashes' );

I have not tested this, it may be wrong, it may have side effects. stripslashes_deep() may eat the extra slashes too …

You should open a bug on Trac if this plugin fixes your problem.

share|improve this answer
So professional! It can add slashed when export, I guess. While, what I want to do is to add slashes when import. Is there any problem if I add slashes in this way when import, rather than when export? (I guess there is. Because if there is not, there will be no need to run stripslashes_deep() when import. I'm a new guy.) Thanks very much! – shuiruge Apr 29 '12 at 11:03
I'm not sure. You would have to apply addslashes before the slashes are stripped … which happens very early. Because once they are removed there is no way to say where they should have been preserved. Changing the export is much easier. – toscho Apr 29 '12 at 11:13
Thank you for your explanation. I will have a try. – shuiruge Apr 30 '12 at 6:57
@shuiruge Any progress? Did it work? – toscho Oct 6 '12 at 22:15
Does anyone have any more information on this ? This is a very nasty bug. – Tarantula Jan 19 '15 at 23:22

I recently ran into this problem as well, and came up with an a solution that worked for me. In your wordpress install folder, browse to the subfolder wp_includes and open post.php. My version contained the line:

$data = wp_unslash( $data );

(The wordpress function reference manual says that wp_unslash is the replacement to the deprecated stripslashes_deep(), so in an older version of wordpress it may be using stripslashes_deep instead of the command above.)

I commented this line out, re-imported, and all my LaTeX backslashes were there. Hope this helps.

share|improve this answer

I found it ended up being easiest to just do a global search and replace for single backslashes to double backslashes in a text editor. I was worried it might escape some important stuff in the XML, so the following bit of PowerShell will tell you the XML tag that surrounded your backslashes.

$r = Select-String '<([^>]*)>.*?\\.*?\1' .\wordpress.2015-09-13.xml -AllMatches
$matches = $r | % { [PSCustomObject] @{ Tag = $_.Matches.Groups[1].Value; LineNumber = $_.LineNumber; Line = $_.Line } }

In my case, all (except one) were HTML tags from the post content itself.

PS> $matches | Foreach-Object Tag | Sort -Unique
font color="#000000"
FONT face="Courier New"
FONT face=Times color=#000000
span style="color: "
span style="color: #000000"
SPAN style="COLOR: #006400"
span style="color: #cccc66; background-color: #012456"
SPAN style="COLOR: blue"
SPAN style="COLOR: green"
SPAN style="COLOR: maroon"

I took a look at the wp:comment_author post (somebody had backslashes in their name), and their name imported fine into that post.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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