X

How to Remove WordPress Shortcodes from Homepage

Snippets by IsItWP

Do you want to strip shortcode from your homepage / index but not from single or archives posts? It’s easy with our code snippet. All you have to do is to copy the snippet to your functions.php file.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

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

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: Best WordPress Page Builders (Compared).

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!