Removing Quote from Text Message - Wordpress

I have a Wordpress site and I want to remove block quotes from the message and post only plain text. (also want to remove any images that are in the text, I just want plain text)

This code makes OPPOSITE what I want - it takes out block quotes and messages that. I want him to publish a different text, not a block quote.

<?php // get the content $block = get_the_content(); // check and retrieve blockquote if(preg_match('~<blockquote>([\s\S]+?)</blockquote>~', $block, $matches)) // output blockquote echo $matches[1]; ?> 
+7
html php wordpress
source share
3 answers

You need a content filter. Add the following to your functions.php file:

 add_filter( 'the_content', 'rm_quotes_and_images' ); function rm_quotes_and_images($content) { $content = preg_replace("~<blockquote>([\s\S]+?)</blockquote>~", "", $content); $content = preg_replace("/<img[^>]+>/i", "", $content); return $content; } 
+1
source share

try it

 add_filter( 'the_content', 'block_the_content_filter' ); function block_the_content_filter($content) { $content = preg_replace("~<blockquote>([\s\S]+?)</blockquote>~", "", $content); return $content; } 
0
source share

Just add this to your code:

 $content = preg_replace("~<blockquote>([\s\S]+?)</blockquote>~", "", $content); $content = strip_tags($content, '<img>'); echo $content; 

As wali hassan said, add the following code to your function. php:

  add_filter( 'the_content', 'block_the_content_filter' ); function block_the_content_filter($content) { $content = preg_replace("~<blockquote>([\s\S]+?)</blockquote>~", "", $content); $content = strip_tags($content, '<img>'); return $content; } 

This overrides the "the_content ()" function by default, so in the page template you only need to call:

 the_content(); 
0
source share

All Articles