Post Content, Special Characters and Filters

I added a hook to the_content.

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

Pretty simple right?

Read More

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.

Example:

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?

Related posts

1 comment

  1. Using a snippet of code like this:

    $hook_name = 'the_content';
    global $wp_filter;
    var_dump($wp_filter[$hook_name]);
    

    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.

Comments are closed.