Remove shortcode from home but not single posts

Adding this snippet to the functions.php of your wordpress theme will strip shortcode from your home page / index but not from single or archives posts.

function remove_shortcode_from_index($content) {
  if ( is_home() ) {
    $content = strip_shortcodes( $content );
  return $content;
add_filter('the_content', 'remove_shortcode_from_index');

Comments  Leave a Reply

  1. hi i am using the Append Comment plugin to add a contact form to the end of every post(using shortcode for contact form). I added your code but it is still appearing on my home page. any ideas?

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!