Merging two excerpt functions to work with conditions

Depending on where in the loop you call excerpt() wpautop might be creating the <p>...</p> wrapper. In that case, you could wrap $excerpt with <p>...</p> before returning it.

Edit: Try this approach <?php echo excerpt(25)."\n";?> (or possibly "\n\n") to change the behavior.

in function awesome_excerpt() you have $text = substr( $content, 0, strpos( $content, '</p>' ) + 4 ); So, $text will have to contain a beginning <p>. That is likely causing what you describe. Add str_ireplace('<p>', '', $excerpt) in function excerpt() before calling explode.

In the current code shown in your question it’s unclear where function excerpt() is being called.

Why not just use the excerpt_length filter to modify the length of the excerpt? From the Codex:

function custom_excerpt_length( $length ) {
return 25;
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );