Support » Fixing WordPress » Excerpt and blocks group

  • When using block group, the excerpt is empty, assuming that there is only content in block group. Is any way to fix this?

    Is there any way to return first paragraph of the content?

    Thanks

    • This topic was modified 2 months, 2 weeks ago by amedic.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @amedic

    You need to add the below-mentioned function in your theme’s function.php file.

    function first_paragraph() {
        global $post, $posts;
        $post_content = $post->post_content;
        $post_content = apply_filters('the_content', $post_content);
        $post_content = str_replace('</p>', '', $post_content);
        $paras = explode('<p>', $post_content);
        array_shift($paras);
    
        return $paras[0]; 
    }

    You need to call this function echo first_paragraph() wherever you want to display the first paragraph of the content.

    Hope this helps.

    Regards,

    • This reply was modified 2 months, 2 weeks ago by vidhiaddweb.

    Hi @ravivaddweb

    thanks for the help, but unfortunately nothing is returned.

    Hi @amedic,

    Can you please let me know did you `echo first_paragraph()’ this function?

    Regards,

    After echoing the function the whole block group is returned. Block group consists of h2, image, custom html and paragraph.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.