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?
You can try with Javascript/jQuery, place this code after DOM loaded or before the closing </body> tag. jQuery('p:empty'). remove(); Will remove all empty <p></p> elements from all over the document.
Create a WordPress Line Break (br) Shortcode You can add a shortcode to fix the line breaks not working issue in WordPress. Insert the following shortcode code into the functions. php file: function add_linebreak_shortcode() { return '<br />'; } add_shortcode('br', 'add_linebreak_shortcode' );
This happens because of WordPress's wpautop
. Simply add below line of code in your theme's functions.php file
remove_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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With