Removing ETX characters in WordPress Posts

Recently I had the issue where an invisible EXT character was appearing in posts and titles. After some investigation, I found out that this EXT character was caused by line breaks in the text created by Photoshop.

In Photoshop when you use SHIFT + ENTER to create a line break, it will add an invisible EXT character into your text. So, if you are copying text from Photoshop (into your WordPress post) that includes this invisible character, it might appear in your browser.

In my case, the EXT character was only appearing on Chrome on Windows. I couldn’t see this invisible character on Chrome on Mac or even in the WordPress text editor, it will, however, show up in Sublime Text.

EXT character in Sublime Text

The solution

You have 2 methods to fixing this issue:

  1. Manual: Copy and paste the offending text (with the EXT character) into Sublime Text and delete the invisible character. Copy and paste the clean text (from Sublime) back into the post/title. You’ll have to repeat this process for every post/title that contains this invisible character.
  2. Automatic: Use a filter hook to automatically remove the EXT character from your post content and titles.

Here’s my function to remove the EXT character from my posts + titles, just paste it into your theme’s functions.php file:

function removeWeirdCharacters($content) {
    $content = preg_replace('/\x03/', '', $content);
    return $content;
} 

add_filter('the_content', 'removeWeirdCharacters');
add_filter('the_title', 'removeWeirdCharacters');

Let me know if this helps! In theory, this function could be updated to find other invisible Unicode characters and remove them as well.

Comments

Comments are closed.