我在回答我自己的问题,以供其他想要这种行为的人参考
If you want to show shortcode as plain text without parsing follow this procedure
add_shortcode( \'my-custom-shortcode\', \'my_custom_function\' );
function my_custom_function(){
global $shortcode_tags;
$tags = $shortcode_tags;
$shortcode_tags = array(); //empty global shortcode tags
$args = array(
\'post_type\' => \'my-cpt\',
\'post_status\' => \'publish\',
\'posts_per_page\' => 10,
\'order\'=> \'ASC\'
);
$posts = new WP_Query( $args );
ob_start();
if( $posts->have_posts() ) {
while ( $posts->have_posts() ) {
$posts->the_post();
the_content(); //Here i do not want to parse (any) shortcode
}
wp_reset_postdata();
}
$shortcode_tags = $tags //reset tags to global variable
return ob_get_clean();
}
If you want to strip shortcode without parsing follow this procedure
add_filter( \'the_content\', \'my_remove_shortcode\' );
function my_remove_shortcode( $content ) {
if( get_post_type() == \'my-cpt\' ) {
$content = strip_shortcodes( $content ); // strip all shortcodes
}
return $content;
}