I have CPT where i do not want to parse shortccode in it's content (using the_content() function). I can use remove_filter to remove default filters for shortcode. but how will i determine that i am removing filter only for my desire CPT?
I have a shortcode [my-custom-shortcode] which i am using in a page. This shortcode use WP_Query and outputting CPT posts. I do not want to parse shortcode inside this CPT posts.
Should i change shortcode with dummy content before shortcode parse hook and replace back after? OR should i remove default filter for shortcode just before my CPT output and again add default filter for shortcodes after my CPT output done?
Or is there any better option?
EDIT: My shortcode looks like this
add_shortcode( 'my-custom-shortcode', 'my_custom_function' );
function my_custom_function(){
$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();
}
return ob_get_clean();
}
function
so thatif ( 'your-cpt' === get_post_type() ) { return ''; }
- i.e. do/output nothing. I mean, if you could modify the Shortcodefunction
code.is parsing shortcode cause any security issue
- yes, it could. So you should use theshortcode_parse_atts()
function, and always sanitize/escape user inputs. E.g. applyesc_url()
on URL addresses.