HOMEBlogTechnical SEOYoast SEO Noindex Pages: 5 Easy Steps to…

Yoast SEO Noindex Pages: 5 Easy Steps to Exclude Specific URLs in Yoast and Rank Math

Yoast SEO Noindex Pages

Some WordPress pages need to stay accessible to visitors while being kept out of search results. You can do this with a small PHP condition and the appropriate Yoast SEO or Rank Math robots filter. This guide shows how to target specific pages with Yoast SEO Noindex Pages code, without changing the indexing behavior of unrelated content.

You will identify the page IDs, add the filter for the SEO plugin that is active on your site, then inspect the rendered robots meta tag to confirm the result. The examples target published WordPress Pages by ID; with careful testing, you can adapt the selection logic for other content types. A noindex directive is not access control: visitors can still open the page, and search engines need to be able to crawl it to discover the directive.

  • PHP 8.0+ and a WordPress site running a current supported release.
  • Yoast SEO or Rank Math installed and active. Use the matching integration rather than enabling both by default.
  • A staging environment or a recent, verified site backup.
  • The WordPress page IDs for the pages that should receive noindex.
  • Access to a child theme or, preferably, a site-specific plugin where you can safely add PHP.

Define the pages and the indexing policy

A noindex directive asks compliant search engines to leave a URL out of search results. It does not prevent visitors from opening the page, and it does not remove access to its content. Before adding code, decide exactly which pages should receive the directive and record their IDs in an explicit allowlist. This narrow selection reduces the risk of changing robots behavior across the rest of the site.

Find an ID by opening a page in the WordPress editor and checking the URL for a value such as post=123. You can also find the ID in the Pages list by hovering over a title and checking the link preview. Replace example IDs in the upcoming snippets with the IDs from your own site. The examples use is_page(), so they target Pages only—not Posts, archives, or custom post types. For other content, use an appropriate conditional such as is_single() for Posts or a carefully specified is_singular() condition. See the official WordPress Conditional Tags reference for how these checks identify the current request.

Keep target URLs crawlable so search engines can fetch the page and discover its noindex directive. Blocking the same URL in robots.txt can prevent crawlers from seeing that instruction, so it is not a substitute for this approach.

Noindex Is Not Privacy
A robots directive is not a security control. Use authentication or appropriate access restrictions for private content; anyone who knows the URL may still be able to visit a page marked noindex.

Implement Yoast SEO Noindex Pages with the Yoast robots filter

Use this implementation when Yoast SEO is the active SEO plugin. It connects the page-selection condition to Yoast’s robots filter, so the selected pages receive a noindex directive while other pages retain their existing robots settings. The Rank Math integration uses a different filter and data format; do not register both integrations by default or run both SEO plugins together without a deliberate configuration.

Before adding code, confirm that the page IDs you collected are correct and decide where the snippet will live. A small site-specific plugin is a durable choice because it keeps the behavior independent of theme changes. A child theme is also suitable if the rule is intentionally tied to that theme. Avoid editing WordPress core or a parent theme: core and theme updates can overwrite changes, and a PHP mistake can affect the whole site.

The next steps separate the reusable page check from the Yoast callback, making the allowlist straightforward to review and update. Add the selector and callback together in the same site-specific plugin or child theme, then test on staging before deployment. If you are following the Yoast-specific path for Yoast SEO Noindex Pages, use only the Yoast callback; use the separate Rank Math section instead when Rank Math is active.

Create a reusable page-selection function

Keep the page condition in one small function so both plugin integrations can use the same allowlist. The IDs below are examples only: replace 123 and 456 with the IDs of the Pages you want to mark noindex. Keeping the list explicit makes the rule easy to audit and avoids accidentally affecting every page, an entire content type, or unrelated URLs.

PHP
if ( ! function_exists( 'pnet_is_noindex_target_page' ) ) {
    function pnet_is_noindex_target_page(): bool {
        // Replace these example IDs with the IDs of your target Pages.
        return is_page( array( 123, 456 ) );
    }
}

The is_page() conditional checks the current front-end request and returns true only when its page ID is in the supplied array. Keep the function in the same site-specific plugin or child theme file as the SEO filter that calls it. The selector does not change robots output by itself; the appropriate Yoast or Rank Math callback must use it. Register only the callback for the SEO plugin you have selected, while the selector itself can be reused with either integration.

Test the condition on a target page and a page outside the list before deploying. This function only determines which page is being viewed; it does not restrict visitors, protect content, or replace authentication. Do not use it as an access-control mechanism.

Filter Yoast robots output

With the page selector in place, connect it to Yoast SEO using the wpseo_robots filter. Add this callback beside pnet_is_noindex_target_page() in the same site-specific plugin or child theme file. The callback changes robots output only when the selector matches a target page.

PHP
add_filter( 'wpseo_robots', 'pnet_filter_yoast_robots' );

function pnet_filter_yoast_robots( $robots ) {
    if ( pnet_is_noindex_target_page() ) {
        return 'noindex, follow';
    }

    // Keep Yoast original robots value for every other page.
    return $robots;
}

On a selected page, the filter returns noindex, follow: search engines are asked not to index the URL, while links on it may still be followed. For every other page, returning the incoming value preserves Yoast’s existing settings and avoids unintentionally changing robots behavior site-wide. Keep this integration enabled only when Yoast SEO is the active plugin; Rank Math uses a separate filter and expects a different return format.

Yoast SEO Noindex Pages - Yoast Filter Setup
Yoast Filter Setup

Implement the Rank Math robots filter

Use this integration when Rank Math is your active SEO plugin. It reuses pnet_is_noindex_target_page(), the page-selection function from the previous step, and connects it to Rank Math’s robots filter. Do not register the Yoast and Rank Math callbacks together by default. Their filters use different return formats, and running both SEO plugins can produce duplicate or conflicting robots output.

Choose One Plugin
Keep only the integration for your active SEO plugin. If both plugins are installed, confirm which one generates the front-end robots meta tag before adding this callback.

Set the Rank Math robots directives

Rank Math passes robots directives as an array, unlike the Yoast filter, which handles a string. Add this callback beside the shared page selector in your site-specific plugin or child theme. It changes the index directive only for selected Pages, keeps an existing follow or nofollow value, and returns the original array for all other requests.

PHP
add_filter( 'rank_math/frontend/robots', 'pnet_filter_rank_math_robots' );

if ( ! function_exists( 'pnet_filter_rank_math_robots' ) ) {
    function pnet_filter_rank_math_robots( $robots ) {
        if ( ! is_array( $robots ) || ! pnet_is_noindex_target_page() ) {
            return $robots;
        }

        $robots['index'] = 'noindex';

        // Preserve an existing follow or nofollow directive.
        if ( ! isset( $robots['follow'] ) ) {
            $robots['follow'] = 'follow';
        }

        return $robots;
    }
}

Replace the example page IDs in the shared selector with your actual IDs. If you keep both integrations in a code library, retain the shared selector but register only the callback for the active plugin. Check the rendered page source after deployment to confirm the target page has a noindex directive and that non-target pages retain their previous robots settings.

You might also like:

WordPress Last Updated Date: The Ultimate Guide to Display Post Modified Date

Want to improve SEO freshness? Learn how to show the WordPress last updated date instead of the published date. Read...

Read more →

Set the Rank Math robots directives

Rank Math passes its robots directives to this filter as an array, so the callback must return an array—not the string used by the Yoast example. Add this code beside the shared pnet_is_noindex_target_page() selector from the previous step. The callback changes only matching Pages, sets their index directive to noindex, and leaves every other robots value untouched unless a follow directive is missing.

PHP
add_filter( 'rank_math/frontend/robots', 'pnet_filter_rank_math_robots' );

if ( ! function_exists( 'pnet_filter_rank_math_robots' ) ) {
    function pnet_filter_rank_math_robots( $robots ) {
        if ( ! is_array( $robots ) || ! pnet_is_noindex_target_page() ) {
            return $robots;
        }

        $robots['index'] = 'noindex';

        // Preserve an existing follow or nofollow directive.
        if ( ! isset( $robots['follow'] ) ) {
            $robots['follow'] = 'follow';
        }

        return $robots;
    }
}

The shared selector must be defined once in the same site-specific plugin or child theme. Replace its example IDs with your actual Page IDs. Keep the Yoast and Rank Math callback names distinct if you retain both integrations in a code library, and register only the callback for the active SEO plugin. Returning the original array for non-target pages prevents this rule from altering their existing robots directives.

Yoast SEO Noindex Pages - Rank Math Filter Preview
Rank Math Filter Preview

Verify the rendered robots directive

After deploying the filter, test both a page in your ID allowlist and a page that is not listed. Open each URL in a logged-out or private browser window so the test reflects what public visitors and crawlers receive, rather than an editor preview. To verify the finished Yoast SEO Noindex Pages implementation, inspect the rendered HTML source—not just the page editor or your PHP condition.

Use the browser’s View Source command or developer tools and search for name="robots". On a target page, confirm the robots meta tag includes noindex; the output may also include follow. On a non-target page, check that your custom rule has not added noindex and that the page retains its intended SEO directives. Pay attention to duplicate robots tags or a combination of index and noindex, which can indicate another plugin, theme, or filter is also changing the output.

  • Clear the page cache, object cache, and CDN cache after deployment.
  • Reload both test URLs and inspect their source again.
  • If the target output is missing, confirm the page ID and active SEO plugin, then check whether the relevant filter runs.
  • If cached or conflicting output remains, temporarily disable competing SEO customizations on staging and repeat the test.

Search engines may take time to recrawl a URL and process a new directive. Keep the page crawlable so crawlers can discover noindex; this setting does not block visits or protect private content. Once the target and non-target checks pass, remove any temporary diagnostics and repeat the verification after future SEO or caching changes.

You might also like:

Easily Add Breadcrumbs in WordPress: The Ultimate Guide (Yoast vs. Custom Code)

Navigation is the backbone of a great user experience. If your visitors feel lost, they leave. It is that simple....

Read more →

Common Errors and Troubleshooting

If a target page does not show noindex, first confirm its WordPress page ID and that the page is a Page, not a post or archive. A wrong ID or mismatched conditional means the selector returns false, so the callback has nothing to change. Test a known target and a page outside the allowlist. If the IDs and page type are correct, confirm the matching SEO plugin is active and that its callback is registered on the correct filter.

Check the filter’s expected return type as well. Yoast’s wpseo_robots integration handles a string; Rank Math’s rank_math/frontend/robots integration expects an array. Returning a string from the Rank Math callback, or attaching its array callback to the Yoast filter, can produce incorrect or missing output. Use only the integration for the active SEO plugin.

Inspect the complete front-end source for duplicate robots meta tags or contradictory index and noindex directives. Another SEO plugin, theme, or custom filter may be generating them. Disable competing customizations on staging one at a time to identify the source. Then purge page, object, and CDN caches and inspect the page again; cached HTML can make a correct code change appear ineffective.

A robots.txt disallow rule may prevent crawlers from fetching a page and seeing its noindex directive. Keep the URL crawlable when you need search engines to process that instruction. Also allow time for recrawling: noindex does not remove a URL from search results immediately, and it does not restrict access to the page content.

If a PHP error appears after adding the snippet, disable it on staging or revert the last change, then verify the active plugin and final HTML before redeploying. Treat noindex as an indexing instruction, never as a substitute for authentication or access controls.

Conclusion

A targeted noindex rule is straightforward when the selection stays explicit: define the Page IDs, connect that allowlist to the filter for your active SEO plugin, and verify the directive in the rendered HTML. The Yoast integration returns a robots string, while Rank Math expects an array, so use the matching callback and do not enable both integrations by default.

Before deploying, check one page that should receive noindex and another that should remain unchanged. This positive and negative test confirms the condition is narrow and that the rest of your site retains its intended robots settings.

  • Back up the site or test the change on staging.
  • Confirm every target Page ID and replace all example IDs.
  • Enable only the callback for the active SEO plugin.
  • Purge page, object, and CDN caches after deployment.
  • Inspect the final HTML source for the expected robots directive.

Keep target URLs crawlable so search engines can discover the directive, and remember that noindex does not protect content from visitors. With the correct plugin filter and a verified allowlist, Yoast SEO Noindex Pages can be managed programmatically without changing unrelated pages.

Abhik

🚀 Full Stack WP Dev | ☕ Coffee Enthusiast | 🏍️ Biker | 📈 Trader
Hi, I’m Abhik. I’ve been coding since 2007, a journey that began when I outgrew Blogger and migrated to a robust self-hosted stack. That transition introduced me to WordPress, and I’ve been building professional solutions ever since.

Leave a comment