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?
相关问题
- Display product ACF field value in Woocommerce tra
- Adding a custom button after add to cart button in
- How to add a “active” class to a carousel first el
- Setting custom order statuses as valid for payment
- change the font size in tag cloud
相关文章
- wordpress新增页面如何个性化设置
- select query in wordpress
- Get WooCommerce featured products in a WP_Query
- Woocommerce update shipping methods in checkout vi
- Change order status just after payment in WooComme
- Publishing or uploading failed. Error message: “Th
- Facebook Login With WP JWT Auth
- Wordpress development process
Sometimes removing WordPress's wpautop function in your theme's functions.php doesn't work (for some reasons).
So I have another solution how to stop removing
<br>
tags or double (<br><br>
) line breaks./wp-content/themes/your_theme_name/functions.php
Add 2 lines to the top of your functions.
This will initially turn off
wpautopop
function.Make changes in file
/wp-includes/formatting.php
in functionwpautop
.A) Change
function wpautop( $pee, $br = true)
tofunction wpautop( $pee, $br = false)
.This will additionally turn off
wpautopop
function from all places.B) Change
$pee = preg_replace('|<br\s*/?>\s*<br\s*/?>|', "\n\n", $pee);
toThis will prevent the system from removing double
<br>
tags. (I know the code is strange but simple//$pee
doesn't help here because of?>
tag).C) Change
$pee = preg_replace("/\n\n+/", "\n\n", $pee);
to//$pee = preg_replace("/\n\n+/", "\n\n", $pee);
This will prevent the system from removing multiple line breaks.
D) Change this:
to that:
This will prevent the system from removing line breaks after the opening or before the closing block element tag like
<div>
,<article>
, etc.E) Change this:
to that:
Pretty the same: This will prevent the system from removing line breaks after the opening or before the closing block element tag like
<div>
,<article>
, etc.F) Change this:
to that:
This will prevent the system from removing
<br>
at the end of the block.G) Change this:
to that:
This will prevent the system from removing
<br>
after an opening or closing block tag.Hope it will help! And read comments in this file – they will help you to understand what you need to turn on or turn off.
Use this code to remove
<p></p>
before editor initialize.use this $editor= wp_filter_nohtml_kses($_POST['editor1']);
As the accepted answer here didn't work for me in WP 4.8.1, I'm posting a workaround that worked for me. I just had to add a class to the p and WordPress won't remove it.
This happens because of WordPress's
wpautop
. Simply add below line of code in your theme's functions.php fileremove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
For more information: http://codex.wordpress.org/Function_Reference/wpautop
I would not recommend using the remove_filter option since it will remove tags and markups everywhere you call them in your template.
Best way is to sanitize your string through PHP
you can use php function strip_tags to remove useless markups:
echo strip_tags(get_the_excerpt()); // Get the raw text excerpt from the current post
or
echo strip_tags(category_description()); // Get the raw text cat desc from the current cat page
this will remove all HTML tags from the current wordpress post when calling it.
you can also add the trim function just in case of:
echo trim(strip_tags(get_the_excerpt())); // Get the raw text excerpt from the current post
or
echo trim(strip_tags(category_description())); // Get the raw text cat desc from the current cat page
this is perfect to get raw text for meta="description" and title where HTML markups are not recommanded.
Hope it helps