Is it possible to filter out only the short code from the message, and then run the short code?
My page looks like this:
[summary img="images/latest.jpg"] This here is the summary [/summary] Lots of text here...
And I just want to display a shortcode on a specific page.
Tried using regular expressions, but they don't seem to work:
$the_query = new WP_Query('category_name=projects&showposts=1'); //loop while ( $the_query->have_posts() ) : $the_query->the_post(); echo '<b>'; the_title(); echo '</b>'; echo '<p>'; $string = get_the_content(); if (preg_match("[\\[[a-zA-Z]+\\][a-zA-Z ]*\\[\/[a-zA-Z]+\\]]", $string , $matches)) { echo "Match was found <br />"; echo $matches[0]; } echo '</p>'; endwhile;
Any idรฉas?
EDIT:
Find a workaround.
while ( $the_query->have_posts() ) : $the_query->the_post(); $content = str_replace(strip_shortcodes(get_the_content()),"",get_the_content()); echo do_shortcode($content); endwhile;
I saw that wordpress had a function for marking up short codes, but not for the contents of the strip. So I replaced the line of split content with the whole post to get only a short code. The only bad thing is that shortcodes should be at the beginning of messages.
source share