How to remove these comments and html tags from the content?

These are actually input fields.paragraph is the textarea field.i query the contents from database and try to show the

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(); ?>

    <li>
        <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>

    </li>

    <?php endwhile; ?>

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(); ?>

    <li>
        <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>

    </li>

    <?php endwhile; ?>
Share Improve this question edited May 7, 2019 at 11:28 tru.d 1861 gold badge1 silver badge17 bronze badges asked May 7, 2019 at 5:22 Bikash GurungBikash Gurung 213 bronze badges 3
  • What can you see when you goto edit post? – Vishwa Commented 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 Commented 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? – Bikash Gurung Commented May 7, 2019 at 9:29
Add a comment  | 

2 Answers 2

Reset to default -1

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.

You can try this:

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

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/reference/functions/sanitize_text_field/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742420644a4440612.html

相关推荐

  • How to remove these comments and html tags from the content?

    These are actually input fields.paragraph is the textarea field.i query the contents from database and try to show the

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信