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>([sS]+?)</blockquote>~', $block, $matches))

        // output blockquote
        echo $matches[1];
?>  

Related posts

3 comments

  1. 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>([sS]+?)</blockquote>~", "", $content);
       $content = preg_replace("/<img[^>]+>/i", "", $content);          
       return $content;
    }
    
  2. Try this

    add_filter( 'the_content', 'block_the_content_filter' );
    function block_the_content_filter($content) {
    
    $content = preg_replace("~<blockquote>([sS]+?)</blockquote>~", "", $content);
    
    return $content;
    
    }
    
  3. Just add this to your code:

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

    The way wali hassan sayed is to add following code to your function.php:

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

    This overrides the default “the_content()” function so in you page template you only need to call:

    the_content();
    

Comments are closed.