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 1 year, 2 months ago by amedic.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Anonymous User 18274256

    (@anonymized-18274256)

    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 1 year, 2 months ago by Anonymous User 18274256.
    Thread Starter amedic

    (@amedic)

    Hi @ravivaddweb

    thanks for the help, but unfortunately nothing is returned.

    Anonymous User 18274256

    (@anonymized-18274256)

    Hi @amedic,

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

    Regards,

    Thread Starter amedic

    (@amedic)

    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)
  • The topic ‘Excerpt and blocks group’ is closed to new replies.