I added a hook to the_content.

add_filter('the_content', 'edit_the_content');
function edit_the_content($content){
    return $content;

Pretty simple right?

However, when it output $content from within my edit_the_content() callback it seems like WordPress converts some, but not all characters into special characters.


it's = it’s

but then an anchor tag, remains untouched and not converted.

Is there some sort of filter which runs on the_content which only converts some characters to special characters, but not all?

  • I would like to know what causes this to happen, but as a short-term solution, I am able to use html_entity_decode($content) to properly check the $content value. – Michael Ecklund Aug 13 '13 at 15:52
  • Hm, not sure... how is the value stored in the database, is it "it's" or "it’s"? – simonthesorcerer Aug 16 '13 at 7:26
  • @simonthesorcerer The value in the database is stored like it's – Michael Ecklund Aug 16 '13 at 16:29
  • @simonthesorcerer In-case you're curious... I found the culprit, along with a solution. – Michael Ecklund Aug 27 '13 at 3:45

Using a snippet of code like this:

$hook_name = 'the_content';
global $wp_filter;

I was able to find a list of all hooked callback functions to the WordPress filter: the_content.

I then located a few possible culprits, then searched for their function existence.

After narrowing down my list, I came to the conclusion on the hooked callback function causing the problem.

In the file ./wp-includes/default-filters.php on line 135 as of WordPress 3.6 there is a hooked function add_filter('the_content', 'wptexturize');

In the file ./wp-includes/formatting.php on line 29 as of WordPress 3.6 there is the function definition of wptexturize().

 * Replaces common plain text characters into formatted entities
 * As an example,
 * <code>
 * 'cause today's effort makes it worth tomorrow's "holiday"...
 * </code>
 * Becomes:
 * <code>
 * &#8217;cause today&#8217;s effort makes it worth tomorrow&#8217;s &#8220;holiday&#8221;&#8230;
 * </code>
 * Code within certain html blocks are skipped.
 * @since 0.71
 * @uses $wp_cockneyreplace Array of formatted entities for certain common phrases
 * @param string $text The text to be formatted
 * @return string The string replaced with html entities

How to prevent WordPress from formatting the_content characters into HTML entities?

remove_filter('the_content', 'wptexturize');

Lesson learned. Using that snippet of code at the beginning of this answer will help you to... at a minimum, find all the attached callback functions to a particular WordPress hook. Which is a great start, the rest may take a bit of searching and reading what each callback function does.

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.