1

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;
}
0

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

UPDATE

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.

2
  • 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? – davidcondrey Jun 20 '14 at 3:21
  • @dcc Check Update – eyoung100 Jun 20 '14 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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