2

I am trying to remove the shortcode from a specific post type, in this case link. I used this code on my functions.php but it removes the shortcode from the_content for every post type.

<?php
function remove_shortcodes( $content )
{
    return strip_shortcodes( $content );
}
add_filter( 'the_content', 'remove_shortcodes' );

is it possible to modify this so it only remove the shortcode from "Link" post type?

thanks

0

You would need to use WordPress Conditional Tags to query if this page is the custom post type you are wanting to target and then if it is remove shortcode.

Untested but you can try this:

    function remove_shortcodes( $content ) {

        if ( get_post_type() == 'post-type-name' ) {
            return strip_shortcodes( $content );
        }
        else 
            return $content;
    }

add_filter( 'the_content', 'remove_shortcodes' );
2
  • 1
    It's interesting that you two both forgot to return the $content when the "if" fails. – Jesse Jun 30 '14 at 14:13
  • Haha yeah you are right :-) – Horttcore Jul 1 '14 at 10:34
1

This will remove shortcodes for the link post type. Maybe you wanna combine it with is_main_query

<?php
function remove_shortcodes( $content )
{
    if ( 'link' == get_post_type() ) // change it to the post type you want
        return strip_shortcodes( $content );
    else
        return $content;

}
add_filter( 'the_content', 'remove_shortcodes' );
?>
1
  • Now returning the content – Horttcore Jul 1 '14 at 10:35

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.