php – How to put “Read more” link in Custom Excerpt inside p tag?

Question

I have a piece of code that extracts the first paragraph from the post, enclosed in a p tag.

I want to add a “Read more” link inside the p tag referring to “the full post“.

Please help.

function first_paragraph() {
  global $post, $posts;
  $first_para="";
  ob_start();
  ob_end_clean();
  $post_content = $post->post_content;
  $post_content = apply_filters('the_content', $post_content);
  $output = preg_match_all('%(<p[^>]*>.*?</p>)%i', $post_content, $matches);
  $first_para = $matches [1] [0];
  echo $first_para;
} 

0
Juniper Scott 2 weeks 2022-01-11T06:35:59-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse