enter image description here

These are actually input fields. paragraph is the textarea field. i query the contents from database and try to show them in this textarea field. But the textarea field is showing me unwanted comments and tags. When I echo them outtside the textarea field, it is fine.

My code....

 <?php while($userNotes->have_posts()): $userNotes->the_post(); ?>

        <input value="<?php echo esc_attr(get_the_title()); ?>" class="note-title-field">

        <span class="edit-note"><i class="fa fa-pencil" aria-hidden="true"></i> Edit</span>

        <span class="delete-note"><i class="fa fa-trash-o" aria-hidden="true"></i> Delete</span>

        <textarea class="note-body-field"><?php echo esc_attr(get_the_content()); ?></textarea>


    <?php endwhile; ?>
  • What can you see when you goto edit post?
    – Vishwa
    May 7, 2019 at 6:10
  • 2
    You see tags because of esc_attr() applied to the post content. If you strip tags from content, you lost text formatting ability from editor (bold, italic, paragraph, etc.).
    – nmr
    May 7, 2019 at 6:19
  • even if i remove esc_attr(), it shows same... I used strip_tags() and it worked but text formatting is lost.. Is there any perfect solution for this? May 7, 2019 at 9:29

2 Answers 2


Can you please try this php function html_entity_decode(get_the_content());. I have used this function on php to remove html tags, you can try this.

  • This fuinction doesn't remove tags, it just changes the entities.
    – fuxia
    May 19, 2020 at 13:34

You can try this:

<textarea class="note-body-field"><?php echo sanitize_text_field(get_the_content()); ?>

I'm also a beginner, but found this works in the frontend. And it seems to be intended for similar use cases - https://developer.wordpress.org/reference/functions/sanitize_text_field/

  • Please explain how that would remove the comments.
    – fuxia
    May 19, 2020 at 13:33

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.