WordPress Snippets at WPcustoms

Prevent dublicate content with conditional noindex

If you handle SEO factors by yourself and not using any seo plugins we found a great snippet for the noindex\index issue. This is a pretty smart solution which takes advantage of conditional tags. The code needs to be placed in your header’s meta section.
In this example it tells the search engines robots to only index and follow the frontpage (no archives), single posts, pages and categories. In this example tags and CPT posts (is_singular(‘movies’)) will have “noindex, follow”. You do have perfect influence which sites you want to be indexed. There is a conditional tag for nearly everything for your perfect SEO strategy to avoid dublicate content.


/**
 * Snippet Name: Prevent dublicate content with conditional noindex
 * Snippet URL: https://wpcustoms.net/snippets/prevent-dublicate-content-conditional-noindex/
 */
  if ((is_home() && ($paged < 2 )) || is_single() || is_page() || is_category()) {
    echo '';
} else {
    echo '';
}