Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a way I can return the shortcode text instead of the output.

My code function is hooked into 'the_content' and I know if my function contain shortcode it will automatically generate the output. I just want to output shortcode text e.g [gallery]

add_filter( 'the_content', 'show_on_front', 10 );
function show_on_front( $content ) {
   $content .= 'this is example of shortcode : [gallery]';
   return $content;
}

Regards,

share|improve this question

3 Answers 3

up vote 1 down vote accepted

Another way is to use a shortcode to display shortcodes :)

add_shortcode('SH','shortcode_display_handler');
function shortcode_display_handler($atts = array(),$content=null){
    $content = str_replace("[","[",$content);
    $content = str_replace("]","]",$content);
    return $content;
}

Usage:

[SH] [gallery] [/SH]
share|improve this answer
1  
Thanks, It's works ! –  resa.r Jan 28 '13 at 16:13

If you want to literally echo "this is example of shortcode : [gallery]" with no shortcode processing then give your filter a very high number for a priority:

add_filter( 'the_content', 'show_on_front', 1000 );

That way, it runs after the shortcode processing function runs.

share|improve this answer
    
Thanks, this is also works. –  resa.r Jan 28 '13 at 16:12

Unless I'm somehow misunderstanding the Question, you could just change [gallery] to [[gallery]].

add_filter( 'the_content', 'show_on_front', 10 );
function show_on_front( $content ) {
   $content .= 'this is example of shortcode : [[gallery]]';
   return $content;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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