Question

What is the best way to strip the_content of html tags and needless spaces on the front end? I'm building a special use theme that needs to allow users who can edit_post to make changes on the front end, but I only want this text area to support plain text.

My current code:

<?php if ( !current_user_can( 'edit_post', $post_ID ) ) : the_content('Read more on "'.the_title('', '', false).'" &raquo;'); else: ?>
        <textarea class="grid_22">
                <?php the_content('Read more on "'.the_title('', '', false).'" &raquo;'); ?>
        </textarea>
<?php endif ?>

produces this: the_content wrapped in a textarea tag

How can I make it look like normal text? Users who edit copy on the front end will not use the backend WYSIWYG editor so I don't have to worry about formats being over written.

Was it helpful?

Solution

You will have to worry about formats beeing over written.

Ex.

<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. ____Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p> <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua._____ At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>

Ends up with having the part between the "_" over written. Even if you edit it as plain text, you will loose the closing and opening paragraph, so two paragraphs become only one.

Everything else you asked for can be done with filters on the_content or get_the_content (please take a look at the codex for further explanation). You'll need to use str_replace or preg_replace (native php functions, please see php.net for explanation) inside those filters.

OTHER TIPS

The HTML tag "textarea" .... takes into account spaces.....

e.g.: https://stackoverflow.com/questions/2202999/why-is-textarea-filled-with-mysterious-white-spaces

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top