0

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,

1

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]
0

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.

0

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

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.