Strip from or something better?

Manipulating HTML with regular expressions is not a good idea. I suggest you use DOMDocument: // input $html = apply_filters(‘the_content’, get_the_content()); $dom = new \DomDocument(); $dom->loadHtml($html); $blockquotes = $dom->getElementsByTagName(‘blockquote’); foreach($blockquotes as $blockquote){ foreach($blockquote->childNodes as $e){ if($e->nodeName === ‘p’){ // create a text node with the contents of the <p> $blockquote->insertBefore($dom->createTextNode($e->textContent), $e); // remove <p> $blockquote->removeChild($e); … Read more

If is_single in functions.php

Generally it’s not a common way to strip wpautop with remove_filter as it is native functionality of WordPress. But if you want to : place the remove_filter() function right before the the_content() function on the pages/templates where you don’t need the wpautop <?php remove_filter( ‘the_content’, ‘wpautop’ ); the_content();?>

remove and then add wpautop

Well, removing autop filter from the_content filter tag makes no sense here, because you never apply the_content filters in your code… Let’s take a look at the source code of the_content() function: function the_content( $more_link_text = null, $strip_teaser = false) { $content = get_the_content( $more_link_text, $strip_teaser ); $content = apply_filters( ‘the_content’, $content ); $content = … Read more

WordPress remove filter wpautop not working

WP’s text widget doesn’t run text through the_content filter, it applies wpautop() on saved text explicitly in code: <div class=”textwidget”><?php echo !empty( $instance[‘filter’] ) ? wpautop( $text ) : $text; ?></div> This is controlled by aptly named “Automatically add paragraphs” setting at the bottom of the widget.

Remove p tags in wordpress posts

The WordPress implementation of the TinyMCE editor automatically adds <p> tags. There’s a few options for removing, as explained in a tutorial on removing <p> tags. I would recommend the following approach, which is a slight modification from that tutorial (as it involves messing with core wp functions). Add the following code to your functions.php … Read more

Shortcodes within the sidebar text/html widget: How to preserve the raw HTML output of the shortcode?

Try this code: add_filter( ‘wp_targeted_link_rel’, ‘__return_false’, 9999 ); function widget_text_replace($text) { $search = array(‘rel=”noopener”‘); $replace = array(”); $text = str_replace($search, $replace, $text); return $text; } add_filter(‘widget_text’, ‘widget_text_replace’);