• I’m writing a word count plugin (my first plugin) and I need to be able to set a variable equal to the content of the post, with all HTML rendered (not & lt; and & gt;). I can’t find the filter to display the post content in the admin panel with HTML tags actually rendered. Here’s how I’ve done it:

    $countpost = apply_filters('the_content', $post->post_content);
    $countpost = attribute_escape($countpost);
    
    // Put "<" and ">" back into any HTML code.
    // WordPress filters otherwise only display "& lt;" and "& gt;"
    $htmlentities = array("<", ">", "&quot;");
    $htmltags   = array("<", ">", '"');
    $countpost = str_replace($htmlentities, $htmltags, $countpost);
    
    // Oddly enough, now we can strip those things we just put back in.
    // Remove white space and html
    $countpost = preg_replace('/\s+/', ' ', strip_tags($countpost));

    There’s got to be an easier way to display the_content instead of displaying it, replacing all & lt; and & gt; with < and >, then doing strip_tags on it.

  • The topic ‘Show Content HTML In Admin Area’ is closed to new replies.