• Problem:

    Go here: https://blog.filmrot.com/
    Note one of the Twitter posts
    Hover the “ReTweet” link – notice that the text inside of the link contains HTML

    I need a way to strip all html from a post. My Google-fu is failing me and I’ve searched the codex and the plugin directory. I even tried to do it with pure PHP. I know there has to be a way to do this, I’m just not finding it. Hoping someone here knows of a method.

    Here is the pure PHP method I tried within TheLoop, with zero result…

    $content2strip = the_content('Read the rest of this entry »');
    echo strip_tags($content2strip);

    Thanks! –James

Viewing 5 replies - 1 through 5 (of 5 total)
  • <?php
    		ob_start();
    		the_content();
    		$old_content = ob_get_clean();
    		$new_content = strip_tags($old_content);
    		echo $new_content;
    ?>
    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Use get_the_content() instead of the_content(), to get the content into a variable.

    Otto42, thanks for the tip re get_the_content(); I wasn’t aware of that function!

    I used:

    <?php
    ob_start();
     the_content(''.__('Read more <span class="meta-nav">&raquo;</span>', 'sandbox').'');
    $old_content = ob_get_clean();
    $new_content = strip_tags($old_content);
    echo $new_content;
    ?>

    without get_the content() and it worked just fine except all the HTML was stripped out of the post- even linebreaks and a drop-cap created in my stylesheet. Basically turned all posts into giant blocks of text with no style, even from my CSS.

    Is there any way to strip out HTML formatting only from text that’s been input via the Dashboard editor? I basically want users to not be allowed to use HTML in their posts.

    To allow some code like <p> and <br /> you add those tags after like this:

    $new_content = strip_tags($old_content, '<p><a><b><br /><input><form><img><textarea><li><ol><ul><table>');

    the above example will allow:
    <p><a><b><br /><input><form><img><textarea><li><ol><ul><table>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Way to strip HTML from the_content ?’ is closed to new replies.