I would like to create a shortcode with parameters which can be used in the WordPress post content. If the shortcode is used, the content should be displayed in the sidebar area! I can suppress the output of the shortcode with ob_end_clean(), but I have no idea how to put this part into the sidebar (I do not want to use the $_GLOBAL var). Is there any clean way to solve this issue?

1 Answer 1


If you wanna show the content in sidebar if current post content has the shortcode then you should try has_shortcode function. Here is a demonstration-

$content = get_the_content();
if( has_shortcode( $content, 'your-shortcode' ) ) {
    // The content has a [your-shortcode] short code, so this check returned true.

Hope it helps.

  • This looks really great, will have to try it though. If I understand this correct, this code part would run in my sidebar within the loop and check if the shortcode is present. I somehow did not think of this solution, just tried to get the output within the shortcode function into sidebar. How would I extract the shortcode with its parameters from the content and run the code? Jan 30, 2017 at 21:54

Your Answer

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

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