Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing block quote from post text - Wordpress

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

This code does the OPPOSITE of what I want - takes out the block quotes and posts that. I want it to post the other text and NOT the 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];
?>  
like image 821
user3550879 Avatar asked Jun 07 '15 01:06

user3550879


People also ask

How do I change the block quote in WordPress?

Highlight the text you would like to make a blockquote. If you are not in the text tab, switch to it. Click on the “b-quote” button and your highlighted text will be made a blockquote. The default blockquote is very basic and will simply center the quote.

How do I indent a block quote in WordPress?

Type the text that you want to appear in the blockquote section of the post. In the post editor, the quoted text is indented. Press "Enter" to move to a new paragraph after typing the text.

How do I change the color of my quotes in WordPress?

Edit the page, click on the separator block, and select a color under the block Color Settings.


1 Answers

What you need is 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;
}
like image 100
Nadav Avatar answered Sep 18 '22 19:09

Nadav