Skip to main content
Login Join
Snippet · PHP

Disable Indexing for Selected Page Templates via Yoast SEO

Shared by Nikul Valani · May 1, 2026 · @wpseo_robots

43 views
3 upvotes
Back to Snippets

Uses the wpseo_robots filter from the Yoast SEO plugin to apply strict robots meta directives (noindex, nofollow, noarchive, nosnippet, etc.) to specific page templates such as product and category landing pages. This prevents these pages from appearing in search results or being crawled, making it ideal for handling duplicate, thin, or conversion-focused content. Runs at priority 999 to override other SEO settings.

<?php
add_filter('wpseo_robots', 'yoast_template_noindex', 999);

function yoast_template_noindex($robots = '') {

    // Add your page templates here
    $templates = [
        'your-template-file.php',
        'another-template-file.php',
    ];

    // Apply noindex rules if current page uses any listed template
    if (is_page_template($templates)) {
        return 'noindex, nofollow, noimageindex, noarchive, nosnippet';
    }

    return $robots;
}
?>
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments