From 72461c99979a4bba269b9f18c71f8451f748af3b Mon Sep 17 00:00:00 2001 From: Marco Almeida Date: Sat, 21 Nov 2026 08:45:33 +0000 Subject: [PATCH 1/2] Treat the WooCommerce cart, checkout and My account pages as noindexed With markdown_alternate_skip_noindexed on, these three pages still got a Markdown version, because is_noindexed() only reads Yoast SEO and Yoast does not mark them noindex on a default setup. WooCommerce keeps them out of search itself, through wp_robots while the HTML page renders, which a Markdown request cannot see. is_noindexed() now passes Yoast's answer through a new filter, markdown_alternate_is_noindexed, and the WooCommerce integration uses it for its cart, checkout and My account pages, matched with wc_get_page_id(). Every place that already honors the opt-in (the .md URL, ?format=markdown, the Accept redirect, the alternate link and llms.txt links) picks them up. Without the opt-in nothing changes. Tests: a standalone test for the filter, and WooCommerce integration checks that the three pages are skipped only with the opt-in and an ordinary page never. PHPStan passes; the baseline only counts the new wc_get_page_id() call. --- README.md | 10 +++++++++- phpstan-baseline.neon | 6 ++++++ readme.txt | 2 ++ src/Integration/WooCommerce.php | 24 ++++++++++++++++++++++++ src/PostTypeSupport.php | 25 ++++++++++++++++++++++++- tests/run.php | 23 +++++++++++++++++++++++ tests/woocommerce-integration.php | 25 +++++++++++++++++++++++++ 7 files changed, 113 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5d98b08..aedcf23 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,15 @@ By default a post keeps its markdown copy even when an SEO plugin marks it noind add_filter( 'markdown_alternate_skip_noindexed', '__return_true' ); ``` -The filter receives the post as its second argument. The check reads Yoast's effective robots value, including an empty robots array or filters that remove noindex; stale per-post metadata does not override that value. Without Yoast active, nothing is skipped. During Yoast llms.txt generation, skipped posts keep their HTML URLs instead of links to unavailable Markdown copies. Regenerate llms.txt after enabling the filter to update an existing file. Markdown responses retain their canonical Link header; this opt-in does not add a blanket noindex header. +The filter receives the post as its second argument. The check reads Yoast's effective robots value, including an empty robots array or filters that remove noindex; stale per-post metadata does not override that value. Without Yoast active, nothing is skipped unless an integration marks the post. With WooCommerce active, the cart, checkout and My account pages count as noindexed, as WooCommerce keeps them out of search itself. During Yoast llms.txt generation, skipped posts keep their HTML URLs instead of links to unavailable Markdown copies. Regenerate llms.txt after enabling the filter to update an existing file. Markdown responses retain their canonical Link header; this opt-in does not add a blanket noindex header. + +Mark other posts as noindexed, for example pages another plugin keeps out of search, with `markdown_alternate_is_noindexed`: + +```php +add_filter( 'markdown_alternate_is_noindexed', function( $noindexed, $post ) { + return $noindexed || 'members-area' === $post->post_name; +}, 10, 2 ); +``` ### Category, tag, and other term archives diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 5c6a595..3aa1e1e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -144,6 +144,12 @@ parameters: count: 1 path: src/Integration/WooCommerce.php + - + message: '#^Function wc_get_page_id not found\.$#' + identifier: function.notFound + count: 1 + path: src/Integration/WooCommerce.php + - message: '#^Function wc_get_product not found\.$#' identifier: function.notFound diff --git a/readme.txt b/readme.txt index dacd83d..1d05ac5 100644 --- a/readme.txt +++ b/readme.txt @@ -116,6 +116,8 @@ Yes, as an opt-in. With `add_filter( 'markdown_alternate_skip_noindexed', '__ret * Prevented visitor-specific Markdown from entering shared caches and invalidated previously generated entries * Moved Markdown response handlers after default-priority access checks and canonical redirects * Added cache-isolation, response-header, and routing-order regression tests +* Added the `markdown_alternate_is_noindexed` filter, to mark posts noindexed by other means than Yoast SEO +* With `markdown_alternate_skip_noindexed` on, the WooCommerce cart, checkout and My account pages get no Markdown version = 1.2.0 = * Added WooCommerce product metadata, formatted prices, short descriptions, visible attributes, and variations diff --git a/src/Integration/WooCommerce.php b/src/Integration/WooCommerce.php index 64087c9..b02eb7b 100644 --- a/src/Integration/WooCommerce.php +++ b/src/Integration/WooCommerce.php @@ -40,6 +40,7 @@ public function register(): void { add_filter( 'markdown_alternate_term_item', array( $this, 'term_item' ), 10, 3 ); add_filter( 'markdown_alternate_term_frontmatter_content_lines', array( $this, 'term_frontmatter' ), 10, 2 ); add_filter( 'markdown_alternate_term_cache_enabled', array( $this, 'term_cache_enabled' ), 10, 2 ); + add_filter( 'markdown_alternate_is_noindexed', array( $this, 'is_noindexed' ), 10, 2 ); } /** @@ -155,6 +156,29 @@ public function term_cache_enabled( $enabled, $term ): bool { return in_array( $term->taxonomy, $this->product_taxonomies(), true ) ? false : (bool) $enabled; } + /** + * Treat the cart, checkout and My account pages as noindexed. + * + * WooCommerce keeps them out of search itself, through wp_robots while the + * HTML page renders, which is not visible from a Markdown request. They + * depend on the customer and have nothing an agent can use. + * + * @param bool $noindexed Whether the post is treated as noindexed. + * @param mixed $post The post being checked. + * @return bool Whether the post is treated as noindexed. + */ + public function is_noindexed( $noindexed, $post ): bool { + if ( $noindexed || ! $post instanceof WP_Post || 'page' !== $post->post_type ) { + return (bool) $noindexed; + } + foreach ( array( 'cart', 'checkout', 'myaccount' ) as $page ) { + if ( (int) wc_get_page_id( $page ) === (int) $post->ID ) { + return true; + } + } + return false; + } + /** * Support product permalinks without exposing standalone variations. * diff --git a/src/PostTypeSupport.php b/src/PostTypeSupport.php index 6cce73e..2734f71 100644 --- a/src/PostTypeSupport.php +++ b/src/PostTypeSupport.php @@ -65,6 +65,29 @@ public static function should_skip_noindexed( \WP_Post $post ): bool { return self::is_noindexed( $post ); } + /** + * Check whether a post is marked noindex. + * + * Reads Yoast SEO, then lets integrations and sites add posts that are + * kept out of search by other means, such as the WooCommerce cart. + * + * @param \WP_Post $post The post to check. + * @return bool True if the post is marked noindex. + */ + public static function is_noindexed( \WP_Post $post ): bool { + /** + * Filters whether a post is treated as noindexed. + * + * Only consulted when the site opts in with markdown_alternate_skip_noindexed. + * + * @since 1.3.0 + * + * @param bool $noindexed Whether Yoast SEO marks the post noindex. + * @param \WP_Post $post The post being checked. + */ + return (bool) apply_filters( 'markdown_alternate_is_noindexed', self::is_noindexed_by_yoast( $post ), $post ); + } + /** * Check whether Yoast SEO marks a post noindex. * @@ -78,7 +101,7 @@ public static function should_skip_noindexed( \WP_Post $post ): bool { * @param \WP_Post $post The post to check. * @return bool True if Yoast marks the post noindex. */ - public static function is_noindexed( \WP_Post $post ): bool { + private static function is_noindexed_by_yoast( \WP_Post $post ): bool { if ( ! function_exists( 'YoastSEO' ) ) { return false; } diff --git a/tests/run.php b/tests/run.php index 8de5a0b..4ee9512 100644 --- a/tests/run.php +++ b/tests/run.php @@ -354,6 +354,29 @@ static function ( $skip, $filtered_post ) use ( $post ) { md_alt_assert_same( false, PostTypeSupport::should_skip_noindexed( $post ), 'indexed' ); }; +$md_alt_tests['Integrations can mark posts noindexed that Yoast indexes'] = static function () { + $post = md_alt_test_fixture( 'ordinary' ); + $GLOBALS['md_alt_test_state']['yoast'] = array( 'index' => 'index' ); + add_filter( + 'markdown_alternate_is_noindexed', + static function ( $noindexed, $filtered_post ) use ( $post ) { + md_alt_assert_same( false, $noindexed, 'Yoast answer' ); + md_alt_assert_same( $post, $filtered_post, 'post' ); + return true; + }, + 10, + 2 + ); + md_alt_assert_same( false, PostTypeSupport::should_skip_noindexed( $post ), 'not opted in' ); + add_filter( + 'markdown_alternate_skip_noindexed', + static function () { + return true; + } + ); + md_alt_assert_same( true, PostTypeSupport::should_skip_noindexed( $post ), 'opted in' ); +}; + $md_alt_tests['Disabling cache ignores existing entries and never stores customer output'] = static function () { $post = md_alt_test_fixture( 'ordinary' ); $renderer = new ContentRenderer(); diff --git a/tests/woocommerce-integration.php b/tests/woocommerce-integration.php index 4b3b197..db65171 100644 --- a/tests/woocommerce-integration.php +++ b/tests/woocommerce-integration.php @@ -318,6 +318,31 @@ function md_alt_woo_render( $id ) { $md_alt_response = wp_remote_get( $md_alt_md_url ); md_alt_woo_assert( 404 === wp_remote_retrieve_response_code( $md_alt_response ) && false === strpos( wp_remote_retrieve_body( $md_alt_response ), 'product_type:' ), 'Unpublished products return 404' ); } + // Cart, checkout and My account count as noindexed, so the opt-in leaves them out. + $md_alt_shop_pages = array_filter( + array_map( 'wc_get_page_id', array( 'cart', 'checkout', 'myaccount' ) ), + static function ( $id ) { + return $id > 0 && get_post( $id ); + } + ); + $md_alt_plain_page = wp_insert_post( + array( + 'post_type' => 'page', + 'post_status' => 'publish', + 'post_title' => 'Markdown test page', + ) + ); + $md_alt_woo_ids[] = $md_alt_plain_page; + foreach ( $md_alt_shop_pages as $md_alt_shop_page ) { + md_alt_woo_assert( PostTypeSupport::is_noindexed( get_post( $md_alt_shop_page ) ) && ! PostTypeSupport::should_skip_noindexed( get_post( $md_alt_shop_page ) ), 'Shop page ' . $md_alt_shop_page . ' is noindexed but kept without the opt-in' ); + } + add_filter( 'markdown_alternate_skip_noindexed', '__return_true' ); + foreach ( $md_alt_shop_pages as $md_alt_shop_page ) { + md_alt_woo_assert( PostTypeSupport::should_skip_noindexed( get_post( $md_alt_shop_page ) ), 'Shop page ' . $md_alt_shop_page . ' is skipped with the opt-in' ); + } + md_alt_woo_assert( ! PostTypeSupport::should_skip_noindexed( get_post( $md_alt_plain_page ) ), 'An ordinary page is not skipped with the opt-in' ); + remove_filter( 'markdown_alternate_skip_noindexed', '__return_true' ); + // Term archives: product categories, nested, with catalog visibility and the list limit. $md_alt_parent_term = wp_insert_term( 'Markdown archive parent ' . wp_generate_uuid4(), 'product_cat' ); $md_alt_child_term = wp_insert_term( 'Markdown archive child ' . wp_generate_uuid4(), 'product_cat', array( 'parent' => $md_alt_parent_term['term_id'] ) ); From 652d94c70f6087e7c70d401f524109264b05f078 Mon Sep 17 00:00:00 2001 From: Joost de Valk Date: Fri, 27 Nov 2026 14:27:06 +0100 Subject: [PATCH 2/2] Mark the is_noindexed filter as new in 1.3.1 1.3.0 was released before this filter was added. Co-Authored-By: Claude Fable 5.2 --- src/PostTypeSupport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PostTypeSupport.php b/src/PostTypeSupport.php index 2734f71..df9957f 100644 --- a/src/PostTypeSupport.php +++ b/src/PostTypeSupport.php @@ -80,7 +80,7 @@ public static function is_noindexed( \WP_Post $post ): bool { * * Only consulted when the site opts in with markdown_alternate_skip_noindexed. * - * @since 1.3.0 + * @since 1.3.1 * * @param bool $noindexed Whether Yoast SEO marks the post noindex. * @param \WP_Post $post The post being checked.