Removing

and
tags in WordPress posts

2019-01-06 10:01发布

Whenever I am posting some content in WordPress post page it is showing some paragraph tags like <p> and <br/>. Which is showing some extra space in output. So is there any solution for it? How to remove all the tags?

标签: wordpress
9条回答
贪生不怕死
2楼-- · 2019-01-06 10:39

Removing the wpautop filter is not the most flexible solution. If you are looking for a page by page solution, or post by post, you can use this plugin:

https://wordpress.org/plugins/dont-muck-my-markup/

It will add a checkbox on every post/page for you to choose if the core-Wordpress behavior will be disabled for that particular page or not.

This is especially useful when you want to post some HTML code and the auto generated <br> and <p> mess up your carefully engineered design.

The plug-in also has a global option so you can have this behavior turned off by default on all pages/posts.

An alternative plug-in is https://wordpress.org/plugins/preserve-code-formatting/ however I only tried the one I described.

查看更多
来,给爷笑一个
3楼-- · 2019-01-06 10:44

try this

$my_postid = $post->ID;
$content_post = get_post($my_postid);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = strip_tags($content, '<p><br/>');
echo $content;
查看更多
▲ chillily
4楼-- · 2019-01-06 10:46

By default, WordPress adds paragraph <p></p> tags to category descriptions. Stop this by adding the following to your functions.php file

// Remove p tags from category description
remove_filter('term_description','wpautop');

Simple and easy (codeless).

Thank you

查看更多
登录 后发表回答