File tree Expand file tree Collapse file tree 1 file changed +26
-6
lines changed Expand file tree Collapse file tree 1 file changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -19,13 +19,33 @@ function is_noindex( $post ) {
1919 return true ; // No post found, treat as noindex.
2020 }
2121
22+ // Check for Yoast SEO noindex.
23+ if ( is_yoast_noindex ( $ post ) ) {
24+ return true ;
25+ }
26+
27+ return false ; // Default to not noindex.
28+ }
29+
30+ /**
31+ * Check Yoast SEO noindex status.
32+ *
33+ * @param \WP_Post|int $post The post object or ID.
34+ * @return bool True if Yoast SEO sets the post to noindex, false otherwise.
35+ */
36+ function is_yoast_noindex ( $ post ) {
37+ if ( ! function_exists ( 'YoastSEO ' ) ) {
38+ return false ; // Yoast SEO is not active.
39+ }
40+
41+ $ post = get_post ( $ post );
42+ $ post_id = $ post ->ID ;
43+
44+ $ robots = YoastSEO ()->meta ->for_post ( $ post_id )->robots ;
2245
23- if ( class_exists ( 'WPSEO_Meta ' ) ) {
24- // Yoast SEO.
25- $ meta_value = \WPSEO_Meta::get_value ( 'meta-robots-noindex ' , $ post ->ID );
26- if ( '1 ' === $ meta_value ) {
27- return true ;
28- }
46+ if ( ! isset ( $ robots ['index ' ] ) ) {
47+ return false ; // No index directive found.
2948 }
3049
50+ return 'noindex ' === $ robots ['index ' ];
3151}
You can’t perform that action at this time.
0 commit comments