Posts import adds non-breaking space to title
-
I noticed that when importing posts to my WordPress.com site via an XML, it has added a non-breaking space to the rendered title. What’s interesting is that it affects all post titles, and only the last space character in the string.
You can see this here: https://public-api.wordpress.com/wp/v2/sites/eatonworksposts.wordpress.com/posts
Look for “title” and then under it, “rendered”.
Any idea why the import is doing this? When I look at the wp-json API on my non-WordPress.com site, and inside the XML, there are no non-breaking spaces.
-
Hi there,
I’m not able to replicate this – I imported some posts from my personal site on WordPress.com, and from a self-hosted WordPress site, to a test site, and the titles all show without that non-breaking space if I view it via the API.
Can you please upload the file you exported from your self-hosted site to https://www.dropbox.com/request/QP79DnyCB9jNd1fBEEIc for me so I can test using that file?
-
-
Thanks for the file.
I was able to replicate the issue on my test site using your file, but then I checked some other sites as well, and I can see that non-breaking space being added in the JSON output for posts that haven’t been imported at all, so it’s not import-related.
After some digging it turns out this happens due to a filter we apply to all post titles on WordPress.com to prevent widowed words in post titles when they’re displayed on a screen. The filter gets applied any time a post title exceeds three words.
That’s why you see it in the email notification for the forum thread as well, as the subject of the email is the title of the forum topic (which is a WordPress custom post type).
So this is intentional and specific to WordPress.com, which is why you won’t see it on your self-hosted site.
If you don’t want it when you display the posts via the API as you explained in your other thread, I’m guessing you should be able to strip that out of the JSON data using regex after you request it. We’re not able to help with the code you’d need for that, though.
-
prevent widowed words in post titles when they’re displayed on a screen
What does that mean exactly?
Thanks for the explanation. I can easily strip the character out. However, I think you should consider the emails a bug since clearly some email clients will not render that character, resulting in a rather ugly subject line.😉
-
A “widow” is when only one word appears on a second line. So this non-breaking space prevents that, and ensures that at least the last two words will always break to the next line if there’s not enough space.
-
Hi, another question I have then is why the non-breaking space isn’t shown in your other API: https://public-api.wordpress.com/rest/v1.1/sites/eatonworksposts.wordpress.com/posts/
-
I’m afraid I don’t know why that filter isn’t used in v1 of our REST API.
For more questions about or help with using our API, please use the contact form at https://developer.wordpress.com/contact/, as we can’t really provide in-depth help on this here in the forums.
- The topic ‘Posts import adds non-breaking space to title’ is closed to new replies.