detector = $detector; } public function register(): void { add_action( 'wp_head', array( $this, 'render' ), 1 ); } /** * Theme functions that print their own description in wp_head. * * Launch test, 2026-10-08 (bakhyzangull.com, Hello Elementor): a page * carried two descriptions — ours and the theme's, from the excerpt, with * different words. When we print one, the theme's is removed; when we have * none, the theme's stays. */ private const THEME_PRINTERS = array( 'hello_elementor_add_description_meta_tag', ); public function render(): void { $description = $this->description_for_request(); if ( '' === $description ) { return; } /** * Theme or plugin functions on wp_head that print a meta description. * * @param string[] $printers Callback names to remove when WPPilot prints one. */ $printers = (array) apply_filters( 'wppilot_theme_description_printers', self::THEME_PRINTERS ); foreach ( $printers as $printer ) { if ( ! is_string( $printer ) ) { continue; } $priority = has_action( 'wp_head', $printer ); if ( false !== $priority ) { remove_action( 'wp_head', $printer, (int) $priority ); } } echo '' . "\n"; } /** * The stored description for the page being viewed, or '' when none should * be printed. */ public function description_for_request(): string { if ( 'fallback' !== $this->detector->detect() ) { return ''; } // Another SEO plugin prints its own description; two would be one too many. if ( null !== $this->detector->other_seo_plugin() ) { return ''; } if ( ! is_singular() ) { return ''; } $post_id = (int) get_queried_object_id(); if ( $post_id <= 0 ) { return ''; } $value = get_post_meta( $post_id, $this->detector->meta_key_for( 'fallback' ), true ); $value = is_string( $value ) ? trim( wp_strip_all_tags( $value ) ) : ''; /** * Whether WPPilot prints its stored meta description on this page. * * @param bool $print Default true. * @param int $post_id The page being viewed. */ if ( '' === $value || ! apply_filters( 'wppilot_print_meta_description', true, $post_id ) ) { return ''; } return $value; } }