Skip to content

Add support for wp_robots hook#72

Draft
wpscholar with Copilot wants to merge 2 commits into
mainfrom
copilot/add-wp-robots-support
Draft

Add support for wp_robots hook#72
wpscholar with Copilot wants to merge 2 commits into
mainfrom
copilot/add-wp-robots-support

Conversation

Copilot AI commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

The plugin was manually echoing a <meta name="robots"> tag via wp_head, bypassing WordPress's native robots directive system introduced in WP 5.7.

Changes

  • filterRobots — New method hooked into wp_robots filter; adds noindex/nofollow directives to the robots array when _hide_from_search_engines meta is set
  • shouldHideFromSearchEngines — Extracted shared condition logic (admin check, blog_public option, valid post ID, meta value) into a protected helper used by both filterRobots and hideFromSearchEngines; adds safety guard for falsy get_the_ID() return
  • setUpHooks — Registers wp_robots filter on WP 5.7+ (detected via function_exists('wp_robots')); falls back to the legacy wp_head echo for older versions
// WP 5.7+: directives merged into WP's robots meta tag
add_filter( 'wp_robots', array( __CLASS__, 'filterRobots' ) );

// Older WP: manual meta tag echo preserved
add_action( 'wp_head', array( __CLASS__, 'hideFromSearchEngines' ), 5 );
Original prompt

This section details on the original issue you should resolve

<issue_title>Add support for wp_robots hook</issue_title>
<issue_description>https://developer.wordpress.org/reference/hooks/wp_robots/</issue_description>

Comments on the Issue (you are @copilot in this section)

@wpscholar Add logic to this function to utilize the wp_robots hook: https://github.com/wpscholar-wp-plugins/mpress-hide-from-search/blob/master/includes/Plugin.php#L67-L77

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: wpscholar <890951+wpscholar@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for wp_robots hook in plugin Add support for wp_robots hook Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for wp_robots hook

2 participants