I've created these two functions to toggle between the first paragraph of the content and then everything but the first paragraph so when the user selects 'More' it slides out the article smoothly without replacing the first paragraph that's already displayed as the excerpt.

However if there's a shortcode in that text it shows up as the shortcode syntax rather than displaying properly. I understand why it's not displaying but I'd like to replace any shortcodes in the text so just show up as text instead of shortcode syntax wrapped in brackets.

function get_first_paragraph(){
    global $post;

    $str = wpautop( str_replace( 'src="http://', 'src="https://', get_the_content() ));
    $str = substr( $str, 0, strpos( $str, '</p>' ) + 4 );
    $str = strip_tags($str, '<a><strong><em>');

    return '<p>' . $str . '</p>';
function get_the_post(){
    global $post;
    $str = wpautop( str_replace( 'src="http://', 'src="https://', get_the_content() ));
    $str = substr( $str, (strpos( $str, '</p>')));
    return $str;

1 Answer 1


Check the $str with get_shortcode_regex(). If $match is returned, you need to parse $str with do_shortcode() and then return it, else false proceed.

  1. GetShortCodeRegEx
  2. DoShortCode


After Sleeping, and while researching to answer your comment, has_shortcode() should be replaced by get_shortcode_regex(), which I have done in my original above.

  • What type of input does that function take? I need to parse it as an object and then convert it to a string or can I just give it the string? Jun 20, 2014 at 3:21
  • @dcc Check Update
    – eyoung100
    Jun 20, 2014 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.